Leonardo Riedel Leonardo Riedel - 1 year ago 92
HTML Question

How to echo the '<?php' in HTML without starting a php section

the Title descripe it:

How to echo the

open tag, without starting a
I tried it with this:

$string = str_replace("<?php","<?php",$string);

I hope someone can help me! :)

Kind regards,

Answer Source

PHP is not recursively embeddable. The following


echo "<?php echo 'Hi mom!' ?>";

Will output the literal characters <, ?, p etc... The "internal" echo will NOT be executed, because it's not PHP code - it's just some characters in a string.

Note that if you're outputting this text into an HTML context (e.g. a web browser), the <?php tag WILL be mis-interpreted as an invalid/illegal HTML tag, and be skipped by the browser. In which case, you have to do

echo "&lt;?php echo 'hi mom!' ?&gt;"

Remember - you're not outputting PHP code, you're outputting text, and if it's going into a web page, that text has to be VALID html.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download