Re: Invalid Characters, XML...
| From: | David Otton | Date: | Mon, 04 Aug 2003 12:17:42 +0000 |
| Subject: | Re: Invalid Characters, XML... | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-158141@lists.php.net to get a copy of this message | ||
On Sun, 3 Aug 2003 21:51:53 -0400 (EDT), you wrote:
>Im using PHP to write to XML files, but I am having some problems. A lot
>of users are cutting and pasting content from text editors like word,
>which uses odd quotation marks, dashes, etc. which PHP writes to the XML
>file, and then the XML parser does not under stand. Is there a
>stripslashes() or htmlspecialchars() equivalent that will convert this
>kind of stuff to the correct ascii text?
This should get you started. It behaves as does htmlentities().
For those high-ASCII characters out of Word/IE... decide what regular ASCII
character you want to map them to, (eg slanted-quote-open and -close to
regular quote), and add them to the $trans array before performing the
array_walk().
function xmlentities ($string, $quote_style = ENT_COMPAT)
{
static $trans;
if (!is_array ($trans)) {
$trans = get_html_translation_table (HTML_ENTITIES, $quote_style);
array_walk ($trans, create_function ('&$a, $b', '$a = "&#" .
ord ($b) .
";";'));
}
return (strtr ($string, $trans));
}