<?php echo "Hello World!"; ?>
should be:
<?php echo "Hello World!"; ?>
How do I do that in PHP?
You need one of these:
html_entity_decode()
htmlspecialchars_decode()
The main difference is that html_entity_decode()
will translate all the HTML entities in your string (<
becomes <
, á
becomes á
, etc.) while html_specialchars_decode()
only translates some special HTML entities:
The converted entities are:
&
,"
(when ENT_NOQUOTES is not set),'
(when ENT_QUOTES is set),<
and>
.
Are you looking for html_entity_decode
?
If you're actually trying to do this manually, instead of with html_entity_decode, try str_replace.
$needle = array("<",">");
$replace = array("<", ">");
$string = '<?php echo "Hello World!"; ?>';
$string = str_replace($needle, $replace, $string);
print $string; // prints <?php echo "Hello World!"; ?>