Snippets v2

Languages
My Snippets

Decoding HTML Entities Login or Register to Bookmark this snippet

Description PHP

Convert all HTML entities to their applicable characters i.e. " => "

The Code Download
  1. <?php
  2. $orig = "I'll "walk" the <b>dog</b> now";
  3.  
  4. $a = htmlentities($orig);
  5. echo $a; // I'll &quot;walk&quot; the &lt;b&gt;dog&lt;/b&gt; now
  6.  
  7. echo $b; // I'll "walk" the <b>dog</b> now
  8.  
  9. // For users prior to PHP 4.3.0 you may do this:
  10.  
  11. function unhtmlentities ($string) {
  12.     $trans_tbl = get_html_translation_table (HTML_ENTITIES);
  13.  
  14.     $trans_tbl = array_flip ($trans_tbl);
  15.  
  16.     return strtr ($string, $trans_tbl);
  17. }
  18.  
  19. $c = unhtmlentities($a);
  20.  
  21. echo $c; // I'll "walk" the <b>dog</b> now
  22.  
  23. ?>
Credits Contact JC

Added by JC on 14th November, 2007

Comments

There are no comments about this snippet.

Post Comment HTML is allowed

You must be registered and logged in to post a comment.

Login here to post a comment