Welcome to collectivesolver - Programming & Software Q&A with code examples. A website with trusted programming answers. All programs are tested and work.

Contact: aviboots(AT)netvision.net.il

Buy a domain name - Register cheap domain names from $0.99 - Namecheap

Scalable Hosting That Grows With You

Secure & Reliable Web Hosting, Free Domain, Free SSL, 1-Click WordPress Install, Expert 24/7 Support

Semrush - keyword research tool

Boost your online presence with premium web hosting and servers

Disclosure: My content contains affiliate links.

39,895 questions

51,826 answers

573 users

How to convert special characters to HTML entities in PHP

4 Answers

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

$s = htmlspecialchars("<a href='I write'>PHP & C & C# & Java Code</a>", ENT_QUOTES);
echo $s; 

/*
run:

&lt;a href=&#039;I write&#039;&gt;PHP &amp; C &amp; C# &amp; Java Code&lt;/a&gt;

*/

 



answered Jun 28, 2016 by avibootz
0 votes
$html = "<p>PHP & 'CSS'</p>";
 
echo htmlspecialchars($html);
 
  
   
/*
run:
 
 
&lt;p&gt;PHP &amp; 'CSS'&lt;/p&gt;
 
*/

 



answered Apr 10, 2024 by avibootz
0 votes
$html = "<p>PHP & 'CSS'</p>";
 
echo htmlspecialchars($html, ENT_QUOTES) . "<br />\n"; // Convert Double and Single Quotes
echo htmlspecialchars($html, ENT_COMPAT) . "<br />\n"; // Convert Double Quotes
echo htmlspecialchars($html, ENT_NOQUOTES) . "<br />\n"; // Don't convert quotes
 
  
   
/*
run:
 
&lt;p&gt;PHP &amp; &#039;CSS&#039;&lt;/p&gt;<br />
&lt;p&gt;PHP &amp; 'CSS'&lt;/p&gt;<br />
&lt;p&gt;PHP &amp; 'CSS'&lt;/p&gt;<br />
 
*/

 



answered Apr 10, 2024 by avibootz
0 votes
$html = '<p>PHP & "CSS"</p>';
 
echo htmlspecialchars($html, ENT_QUOTES) . "<br />\n"; // Convert Double and Single Quotes
echo htmlspecialchars($html, ENT_COMPAT) . "<br />\n"; // Convert Double Quotes
echo htmlspecialchars($html, ENT_NOQUOTES) . "<br />\n"; // Don't convert quotes
 
  
   
/*
run:
 
&lt;p&gt;PHP &amp; &quot;CSS&quot;&lt;/p&gt;<br />
&lt;p&gt;PHP &amp; &quot;CSS&quot;&lt;/p&gt;<br />
&lt;p&gt;PHP &amp; "CSS"&lt;/p&gt;<br />
 
*/

 



answered Apr 10, 2024 by avibootz

Related questions

1 answer 174 views
2 answers 167 views
2 answers 207 views
3 answers 273 views
...