note 92104 modified in function.htmlentities by danbrown

From: Date: Thu, 09 Jul 2009 14:43:52 +0000
Subject: note 92104 modified in function.htmlentities by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-158112@lists.php.net to get a copy of this message
If you want something simple that actually works, try this. Strips MS word and other entities and returns a clear data string: <?php //call this function function DoHTMLEntities ($string) { $trans_tbl[chr(145)] = '&#8216;'; $trans_tbl[chr(146)] = '&#8217;'; $trans_tbl[chr(147)] = '&#8220;'; $trans_tbl[chr(148)] = '&#8221;'; $trans_tbl[chr(142)] = '&eacute;'; $trans_tbl[chr(150)] = '&#8211;'; $trans_tbl[chr(151)] = '&#8212;'; return strtr ($string, $trans_tbl); } //insert your string variable here $foo = str_replace("\r\n\r\n","",htmlentities($your_string)); $foo2 = str_replace("\r\n"," ",$foo); $foo3 = str_replace(" & ","&amp;",$foo2); echo DoHTMLEntities ($foo3); ?> --was-- If you want something simple that actually works, try this. Strips MS word and other entities and returns a clear data string: //call this function function DoHTMLEntities ($string) { $trans_tbl[chr(145)] = '&#8216;'; $trans_tbl[chr(146)] = '&#8217;'; $trans_tbl[chr(147)] = '&#8220;'; $trans_tbl[chr(148)] = '&#8221;'; $trans_tbl[chr(142)] = '&eacute;'; $trans_tbl[chr(150)] = '&#8211;'; $trans_tbl[chr(151)] = '&#8212;'; return strtr ($string, $trans_tbl); } //insert your string variable here $foo = str_replace("\r\n\r\n","",htmlentities($your_string)); $foo2 = str_replace("\r\n"," ",$foo); $foo3 = str_replace(" & ","&amp;",$foo2); echo DoHTMLEntities ($foo3); http://php.net/manual/en/function.htmlentities.php

« previous php.notes (#158112) next »