Re: HTMLEntities as NUMERIC for XML
| From: | Al | Date: | Tue, 25 Nov 2008 16:43:50 +0000 |
| Subject: | Re: HTMLEntities as NUMERIC for XML | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-283806@lists.php.net to get a copy of this message | ||
ceo@l-i-e.com wrote:
After reading this: http://validator.w3.org/feed/docs/error/UndefinedNamedEntity.html (all praise W3.org!) I am searching for a PHP library function that will convert all my &abc; into { I have a zillion of these things from converting stupid MS Word characters into something that will, like, you know, actually WORK on the Internet, and do not really want to re-invent the wheel here. Somebody has to have written this function... I'm kind of surprised it's not http://php.net/xmlentities or somesuch...Here's what I use: //Translate table for dumb Windows chars when user paste from Word; function strips all >160 $win1252ToPlainTextArray=array( chr(130)=> ',', chr(131)=> '', chr(132)=> ',,', chr(133)=> '...', chr(134)=> '+', chr(135)=> '', chr(139)=> '<', chr(145)=> '\'', chr(146)=> '\'', chr(147)=> '"', chr(148)=> '"', chr(149)=> '*', chr(150)=> '-', chr(151)=> '-', chr(155)=> '>', chr(160)=> ' ', ); function cleanWin1252Text($str) {
global $win1252ToPlainTextArray; //translate array for many dumb Windows special chars; used for paste in textarears
$str = strtr($str, $win1252ToPlainTextArray);
$str = trim($str);
$patterns = array('%[\x7F-\x81]%', '%[\x83]%', '%[\x87-\x8A]%', '%[\x8C-\x90]%', %[\x98-\xff]%');
return preg_replace($patterns, '', $str); //Strip
}