suppose i have a variable in a seperate php file i.e
$imgfile = "images/img.jpg";
now i have a php file where i am including a html or another php file i.e
<?php
include("foo.html");
?>
and in foo.html i have the following code..
<html>
<head>
<title>foo site</title>
</head>
<body>
<img src="<?php echo $imgfile; ?>">
and it is works but i am including that $imgfile many times so i want not to type
<?php echo $imgfile; ?> again and again.. i have seen many scripts that include such files by just typing {$imgfile} but i don’t know how to use it please let me know how can i use such a format..??
PHP is a template engine already.
so, it has shorter form for
echostatement, especially for this purpose:considerable shorter and comparable to
{$imgfile}Note that to make use of brackets, you’ll have to devise alternatives for loops, conditions and other statements, which will complicate your life.
while using PHP as a template, you’ll be able to use built-in PHP operators, like
foreachorifor include.So, it would be better to stick to
<?=$imgfile?>syntax.Just make sure you have
short_open_tagssetting turned on