Certain characters such as (&, ", ', <, >) have special significance in HTML, and should be converted to HTML entities. You can use the PHP htmlspecialchars() function to convert special characters in a string to HTML entities. Let's check out an example:
<?php
$my_str = "String with <b>special</b> characters.";
// Removing HTML special characters
echo htmlspecialchars($my_str);
?>
If you view the source code of the output you will the string "String with <b>special</b> characters." converted to "String with <b>special</b> characters."
Use the PHP
htmlspecialchars()functionCertain characters such as (
&,",',<,>) have special significance in HTML, and should be converted to HTML entities. You can use the PHPhtmlspecialchars()function to convert special characters in a string to HTML entities. Let's check out an example:If you view the source code of the output you will the string "String with <b>special</b> characters." converted to "String with <b>special</b> characters."
need an explanation for this answer? contact us directly to get an explanation for this answer