问题
<?php echo "Hello World!"; ?>
should be:
<?php echo "Hello World!"; ?>
How do I do that in PHP?
回答1:
You need one of these:
html_entity_decode()
htmlspecialchars_decode()
- html_entity_decode() in PHP Manual
- htmlspecialchars_decode() in PHP Manual
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>
.
回答2:
htmlspecialchars_decode()
回答3:
Are you looking for html_entity_decode?
回答4:
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!"; ?>
来源:https://stackoverflow.com/questions/6665985/how-to-convert-characters-to-html-characters