Re: Convert Characters

From: Date: Mon, 29 Mar 2004 20:46:12 +0000
Subject: Re: Convert Characters
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-181715@lists.php.net to get a copy of this message
Reuben Sant wrote:
Hi, Is there a way to convert any character to it's HTML &#xxx; equivalent in PHP? For example A is the letter "A" where the number 65 represents it's ASCII code.
This may help. It's a function from Tom Rogers, or was it Tim Rogers, I can't remember. function clean_ms_word($original) {
    $crap = array(chr(0x82),chr(0x83),chr(0x84),chr(0x85),chr(0x86),chr(0x87),chr(0x88),chr(0x89),chr(0x8a),chr(0x8b),chr(0x8c),chr(0x91),chr(0x92),chr(0x93),chr(0x94),chr(0x95),chr(0x96),chr(0x97),chr(0x98),chr(0x99),chr(0x9a),chr(0x9b),chr(0x9c),chr(0x9f));
    $clean = array('‚','ƒ','„','&ldots;','†','‡','','‰','Š','‹','Œ','‘','’','"','"','•','–','—','˜','™','š','›','œ','Ÿ');
    $content = str_replace($crap,$clean,$writing);
    return $content;
} $new = clean_ms_word($original); $crap is the stuff you don't want. $clean is the stuff you want. So, chr(0x82) would become &lsquor. HTH, Roger

« previous php.general (#181715) next »