HTML_Entities
[ class tree: HTML_Entities ] [ index: HTML_Entities ] [ all elements ]

Source for file html_entities_example.php

Documentation is available at html_entities_example.php

  1. <html>
  2. <head><title>HTML_Entities example</title></head>
  3. <body>
  4. <?php
  5.  
  6. error_reporting(E_STRICT);
  7. ini_set('display_errors'true);
  8.  
  9. require_once "HTML/Entities.php";
  10.  
  11. // 1. Define a text (utf8) we want to convert to entities:
  12. $t "Le français est une langue qui nécessite des caractères spéciaux.";
  13.  
  14. // 2. Convert it to HTML entities:
  15. $t HTML_Entities::encode($t);
  16. echo "<p>".$t."</p>";
  17.  
  18. // 3. Convert it back to latin1:
  19. try {
  20. $t HTML_Entities::decode($tHTML_Entities::ALL"latin1");
  21. }
  22. catch (PEAR_Exception $e{
  23. }
  24. echo "<p>".$t."</p>";
  25.  
  26. // 4. Write the list of entities
  27.  
  28. echo "<table>";
  29. foreach ($table as $char=>$entity{
  30.     echo "<tr><td>{$char}</td><td>";
  31.     echo HTML_Entities::encode($entity);
  32.     echo "</td></tr>";
  33. }
  34. echo "</table>";
  35.  
  36. ?>
  37. </body></html>

Documentation generated on Mon, 11 Mar 2019 15:21:39 -0400 by phpDocumentor 1.4.4. PEAR Logo Copyright © PHP Group 2004.