Domanda

Is there a way to mix html and php variables easily? This is the kind of thing I am trying to do:

<p><strong>Organisation Name:</strong> {$_SESSION['org-name']}</p>

Is this possible without using a templating engine for PHP like Smarty?

È stato utile?

Soluzione

The simplest possible solution I can think of is using the php shorttag, and some kind of MVC (or at least VC) structure:

view.php

<div>
My name is <?= $myName ?>
</div>

main.php

$myName = 'John'; //or $_SESSION['myName'] or whatever
include 'view.php'; // after include the variable $myName will be visible inside of view.php
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top