note 98697 modified in function.html-entity-decode by danbrown

From: Date: Thu, 01 Jul 2010 13:05:30 +0000
Subject: note 98697 modified in function.html-entity-decode by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-170624@lists.php.net to get a copy of this message
Handy function to convert remaining HTML-entities into human readable chars (for entities which do not exist in target charset): <?php function cleanString($in,$offset=null) { $out = trim($in); if (!empty($out)) { $entity_start = strpos($out,'&',$offset); if ($entity_start === false) { // ideal return $out; } else { $entity_end = strpos($out,';',$entity_start); if ($entity_end === false) { return $out; } // zu lang um eine entity zu sein else if ($entity_end > $entity_start+7) { // und weiter gehts $out = cleanString($out,$entity_start+1); } // gottcha! else { $clean = substr($out,0,$entity_start); $subst = substr($out,$entity_start+1,1); // &scaron; => "s" / &#353; => "_" $clean .= ($subst != "#") ? $subst : "_"; $clean .= substr($out,$entity_end+1); // und weiter gehts $out = cleanString($clean,$entity_start+1); } } } return $out; } ?> --was-- Handy function to convert remaining HTML-entities into human readable chars (for entities which do not exist in target charset): function cleanString($in,$offset=null) { $out = trim($in); if (!empty($out)) { $entity_start = strpos($out,'&',$offset); if ($entity_start === false) { // ideal return $out; } else { $entity_end = strpos($out,';',$entity_start); if ($entity_end === false) { return $out; } // zu lang um eine entity zu sein else if ($entity_end > $entity_start+7) { // und weiter gehts $out = cleanString($out,$entity_start+1); } // gottcha! else { $clean = substr($out,0,$entity_start); $subst = substr($out,$entity_start+1,1); // &scaron; => "s" / &#353; => "_" $clean .= ($subst != "#") ? $subst : "_"; $clean .= substr($out,$entity_end+1); // und weiter gehts $out = cleanString($clean,$entity_start+1); } } } return $out; } http://php.net/manual/en/function.html-entity-decode.php

« previous php.notes (#170624) next »