RE: [PHP] Invalid Characters, XML...
| From: | Luis Lebron | Date: | Mon, 04 Aug 2003 13:30:26 +0000 |
| Subject: | RE: [PHP] Invalid Characters, XML... | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-158147@lists.php.net to get a copy of this message | ||
Here's what I have been using.
$trans= array("'" => "'", "'" =>
"'",">" => ">", "<" =>
"<",
"&" => "&","-" => "-",
"°" => "°", "±" => "±",
"-" =>
"–", """ => "“", """ =>
"”","..." => "…","'" =>
"‘","²" =>"²","·" =>
"·" );
$value=strtr($value,$trans);
Luis
-----Original Message-----
From: David Otton [mailto:phpmail@jawbone.freeserve.co.uk]
Sent: Monday, August 04, 2003 7:18 AM
To: Russell P Jones
Cc: php-general@lists.php.net
Subject: Re: [PHP] Invalid Characters, XML...
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));
}
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php