How to convert all applicable characters to HTML entities in PHP

3 Answers

0 votes
// string htmlentities( string $string [, int $flags = ENT_COMPAT | ENT_HTML401 
//                       [, string $encoding = ini_get("default_charset") 
//                       [, bool $double_encode = true ]]])


$s = "I'll \"write\" 'the' <b>php</b> code";

echo htmlentities($s) . "<br />\n";
echo htmlentities($s, ENT_QUOTES);

/*
run:

I'll "write" 'the' <b>php</b> code
I'll "write" 'the' <b>php</b> code


I'll &quot;write&quot; 'the' &lt;b&gt;php&lt;/b&gt; code<br />
I&#039;ll &quot;write&quot; &#039;the&#039; &lt;b&gt;php&lt;/b&gt; code

*/

 



answered Jun 28, 2016 by avibootz
0 votes
// string htmlentities( string $string [, int $flags = ENT_COMPAT | ENT_HTML401 
//                       [, string $encoding = ini_get("default_charset") 
//                       [, bool $double_encode = true ]]])


$s = "I'll \"write\" 'the' <b>php</b> code";

echo htmlentities($s, ENT_QUOTES, "UTF-8"). "<br />\n";
echo htmlentities($s, ENT_QUOTES | ENT_IGNORE, "UTF-8");

/*
run:

I'll "write" 'the' <b>php</b> code
I'll "write" 'the' <b>php</b> code


I&#039;ll &quot;write&quot; &#039;the&#039; &lt;b&gt;php&lt;/b&gt; code<br />
I&#039;ll &quot;write&quot; &#039;the&#039; &lt;b&gt;php&lt;/b&gt; code

*/

 



answered Jun 28, 2016 by avibootz
0 votes
// string htmlentities( string $string [, int $flags = ENT_COMPAT | ENT_HTML401 
//                       [, string $encoding = ini_get("default_charset") 
//                       [, bool $double_encode = true ]]])


$s = "\x8F!!";

echo htmlentities($s, ENT_QUOTES, "UTF-8"). "<br />\n";
echo htmlentities($s, ENT_QUOTES | ENT_IGNORE, "UTF-8");

/*
run:

<br />
!!

*/

 



answered Jun 28, 2016 by avibootz

Related questions

1 answer 200 views
2 answers 203 views
2 answers 236 views
4 answers 492 views
1 answer 195 views
...