string htmlspecialchars function - it converts all special characters to HTML entities

string htmlspecialchars function - it converts all special characters to HTML entities

string-htmlspecialchars-function-in-php.php


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
 <head>
  <title>string htmlspecialchars function - it converts all special characters to HTML entities</title>
  <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
  <meta name="Author" content="Md Iqbal Hosan">
  <meta name="title" content="string htmlspecialchars function - it converts all special characters to HTML entities">
  <meta name="keywords" content="php, example, code, array, function, htmlspecialchars, string">
  <meta name="description" content="string htmlspecialchars function - it converts all special characters to HTML entities">
  <style>
   h2, h4{background:#eee; color:#000085;}
   h2{ padding:3px; margin:3px; font-size:22px;}
   h4{ padding:2px; margin:2px; font-size:19px;}
   p{padding:2px; margin:2px; color:#330100;}
   body{ background:#FFFFFa;}
   span{ background:orange;}
  </style>
 </head>
 <body>
  <h2>string htmlspecialchars function - it converts all special characters to HTML entities</h2>
  <pre>
   <?php
    /*
     ---------------------------------------------------------
     let us make string with some special character for test
     ---------------------------------------------------------
    */
    $myString = "my boss <span>cfsuman</span> is sick. my fellows <span>&</span> me pray for him to cheer-up.";
    echo "<h4>Output of myString in the browser</h4>";
    print "<p>$"."myString = {$myString}</p>";
    print "<p>string length : ".strlen($myString)."</p>";
    /*
     ------------------------------------------------------------------------------
     i want to convert all special characters to their equivalent html entities 
     by using htmlspecialchars string function
     ------------------------------------------------------------------------------
    */
    $convertedString = htmlspecialchars($myString);
    echo "<h4>Output of convertedString by using string htmlspecialchars function</h4>";
    print "<p>$"."convertedString = {$convertedString}</p>";
    print "<p>string length : ".strlen($convertedString)."</p>";
    /*
     --------------------------------------------------------------------------------------------
     professionally this function is used rapidly to convert special characters to html entities
     --------------------------------------------------------------------------------------------
    */
   ?>
  </pre>
 </body>
</html>

string htmlspecialchars function - it converts all special characters to HTML entities - output in the browser

No comments:

Post a Comment

leave your comments here..