note 37614 added to function.htmlentities
| From: | marcus at synchromedia dot co dot uk | Date: | Thu, 20 Nov 2003 20:18:22 +0000 |
| Subject: | note 37614 added to function.htmlentities | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-60720@lists.php.net to get a copy of this message | ||
The function below does a direct MacRoman to ISO 8859-1 charset conversion. It also avoids the
problem of having to have foreign chars in your scripts (see user notes for strtr()) by using hex
character codes. Make sure you remove all the line breaks from within the conversion strings.
This is posted as an alternative to the script provided by dmurphy at telegeography dot com in the
notes for this function, rather than the notes for strtr (perhaps I should post it in both places?).
That script is pretty inefficient, particulaly as many strings will be shorter than the table
that's scanned on every pass, and he forgot to quote 'key' and 'value'. It
does have the advantage of handling 'odd' charcters quite neatly though.
/**
* Convert MacRoman encoded string into an ISO-8859-1 encoded string
* Loses a few odd chars (ligatures etc) that are not in ISO 8859-1
* Adapted from http://www.entropy.ch/software/
* perl/conversion-scripts/convert_mac2iso.pl.txt
*/
function macroman2iso($macstring){
return strtr($macstring,
"\\x80\\x81\\x82\\x83\\x84\\x85\\x86\\x87\\x88\\x89\\x8a\\x8b
\\x8c\\x8d\\x8e\\x8f\\x90\\x91\\x92\\x93\\x94\\x95\\x96\\x97\\x98
\\x99\\x9a\\x9b\\x9c\\x9d\\x9e\\x9f\\xa1\\xa4\\xa6\\xa7\\xa8
\\xab\\xac\\xae\\xaf\\xb4\\xbb\\xbc\\xbe\\xbf\\xc0\\xc1\\xc2\\xc7\\xc8
\\xca\\xcb\\xcc\\xd6\\xd8\\xdb\\xe1\\xe5\\xe6\\xe7\\xe8\\xe9\\xea\\xeb
\\xec\\xed\\xee\\xef\\xf1\\xf2\\xf3\\xf4\\xf8\\xfc",
"\\xc4\\xc5\\xc7\\xc9\\xd1\\xd6\\xdc\\xe1\\xe0\\xe2\\xe4\\xe3
\\xe5\\xe7\\xe9\\xe8\\xea\\xeb\\xed\\xec\\xee\\xef\\xf1\\xf3\\xf2\\xf4
\\xf6\\xf5\\xfa\\xf9\\xfb\\xfc\\xb0\\xa7\\xb6\\xdf\\xae\\xb4\\xa8
\\xc6\\xd8\\xa5\\xaa\\xba\\xe6\\xf8\\xbf\\xa1\\xac\\xab\\xbb
\\xa0\\xc0\\xc3\\xf7\\xff\\xa4\\xb7\\xc2\\xca\\xc1\\xcb\\xc8\\xcd
\\xce\\xcf\\xcc\\xd3\\xd4\\xd2\\xda\\xdb\\xd9\\xaf\\xb8"
);
}
----
Manual Page -- http://www.php.net/manual/en/function.htmlentities.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+37614
Delete -- http://master.php.net/manage/user-notes.php?action=delete+37614&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+37614&report=yes
Search -- http://master.php.net/manage/user-notes.php