PHP htmlspecialchars() Function

Today, We want to share with you htmlspecialchars.In this post we will show you htmlspecialchar vs htmlentities, hear for htmlspecialchar javascript we will give you demo and example for implement.In this post, we will learn about How To Remove All Special Characters From A String In Php? with an example.

HTML Encoding With htmlspecialchar and htmlentities

  • & (ampersand) converted as &
  • (double quote) converted as "
  • (single quote) converted as '
  • < (less than) converted as &lt;
  • > (greater than) converted as &gt;
Read Also:  how to dynamically Add and Delete rows dynamically using angularjs?

PHP Function

<!DOCTYPE html>
<html>
<body>

<?php
$str = "Jayshree & 'Krishna'";
echo htmlspecialchars($str, ENT_COMPAT); // Will only convert double quotes
echo "<br>";
echo htmlspecialchars($str, ENT_QUOTES); // Converts double and single quotes
echo "<br>";
echo htmlspecialchars($str, ENT_NOQUOTES); // Does not convert any quotes
?>

</body>
</html>

PHP : function

<?php
$convert = "<li><a href='index.php'>Welcome To Free Download Source code php</a></li>";
echo "Original string : ".$convert;
echo "<br />";
htmlspecialchars("<li><a href='index.php'>Welcome To Free Download Source code php</a></li>", ENT_QUOTES);
echo "Only HTML special characters : ".htmlspecialchars($convert);
?>

PHP String Function

<? php  
    //string conversion example of htmlspecialchar () function  
$str = "Welcome to <i>pakainfo</i> text.";  
echo htmlspecialchars($str, ENT_QUOTES);    //Will convert both single and double-quotes.  
?>  

I hope you get an idea about PHP htmlspecialchar Function.
I would like to have feedback on my infinityknow.com blog.
Your valuable feedback, question, or comments about this article are always welcome.
If you enjoyed and liked this post, don’t forget to share.

Read Also:  How to fetch image from database in php ?

Related FAQ

Here are some more FAQ related to this Article:

  1. Read Also:  Dynamic and Dependent Dropdown list using AngularJS with PHP
  2. Read Also:  Laravel Send Mailgun Mail using PHP cURL
  3. Read Also:  PHP MYSQLi Import Data From Excel to MYSQL
  4. Read Also:  Dynamically Add-remove Form Fields in jquery with PHP and mysql
  5. Read Also:  Server-side processing Laravel DataTables
  6. Read Also:  Laravel 6 - Simple Pagination Example Tutorial
  7. Read Also:  Validating Woocommerce webhook using HMAC in PHP
  8. Read Also:  Laravel 6 orderBy for Multiple columns
  9. Read Also:  Dynamically Add-remove Form Fields in jquery with PHP and mysql
  10. Read Also:  Laravel Send Mailgun Mail using PHP cURL
CLOSEX