PHP: How to print php syntax in html

I am wondering if php syntax can be printed on an html page. For example below is the php syntax that I want to echo on an html page through php.

Please <?php echo $random[array_rand($random)]; ?> the [url=http://feeds.feedburner.com]hello[/url].<br> Also [url=http://feeds.feedburner.com]<?php echo $random[array_rand($random)]; ?>[/url]. <br> 
+4
source share
5 answers

Try the following:

 <?php $str='Please <?php echo $random[array_rand($random)]; ?> the [url=http://feeds.feedburner.com]hello[/url].<br> Also [url=http://feeds.feedburner.com]<?php echo $random[array_rand($random)]; ?>[/url]. <br>'; echo highlight_string($str); ?> 

Output:

highlights

+13
source

use htmlspecialchars to print php syntax in html

 echo htmlspecialchars('<?php echo "Hello, World!"; ?>'); 

Output

 <?php echo "Hello, World!"; ?> 

Demo

+1
source

Use highlight_string to highlight syntax

+1
source

Use symbolic links for characters with a special meaning.

&lt;php echo etc.

0
source

If you want to print it from a file, use

 highligh_code($filename); 
0
source

Source: https://habr.com/ru/post/1479682/


All Articles