Convert Special Characters To HTML Entities PHP

Convert Special Characters To HTML Entities PHP

In this tutorial we will learn How to Convert Special Characters To HTML Entities in PHP. PHP built-in htmlspecialchars() function is used to convert some special characters to HTML entities.

Using htmlspecialchars() Function

We can simply use htmlspecialchars() Function to convert special characters to HTML Entities.

htmlspecialchars() Function is a built-in PHP function which converts some predefined characters to HTML entities.

Take a look at the code given below.

<?php
$string = "This is <b>HowToCodeSchool.com</b>.";
echo htmlspecialchars($string);
?>

$string variable contains HTML entities which were converted from special characters.

Output

This is &lt;b&gt;HowToCodeSchool.com&lt;/b&gt;

Some Special Characters are:

  • &
  • "
  • '
  • <
  • >

Their HTML Entities are:

  • &amp;
  • &quot;
  • &#039;
  • &lt;
  • &gt;

Comments

Popular posts from this blog

Gove confirms mandatory housebuilding targets for councils will be abolished in face of Tory rebellion – UK politics live

Kotak Mahindra Bank Recruitment 2022 Released for Graduate Candidates And Apply Online