note 40481 added to function.htmlentities

From: Date: Thu, 04 Mar 2004 23:11:17 +0000
Subject: note 40481 added to function.htmlentities
Groups: php.notes 
Request: Send a blank email to php-notes+get-66279@lists.php.net to get a copy of this message
This version of macRomanToIso (originally posted by: marcus at synchromedia dot co dot uk) offers a couple of improvements. First, it removes the extra slashes '\' that broke the original function. Second, it adds four quote characters not supported in ISO 8859-1. These are the left double quote, right double quote, left single quote and right single quote. Be sure to remove the line breaks from the two strings going into strtr or this function will not work properly. Be careful what text you apply this to. If you apply it to ISO 8859-1 encoded text it will likely wreak havoc. I'll save you some trouble with this bit of advice: don't bother trying to detect what charset a certain text file is using, it can't be done reliably. Instead, consider making assumptions based upon the HTTP_USER_AGENT, or prompting the user to specify the character encoding used (perhaps both). <?php /** * Converts MAC OS ROMAN encoded strings to the ISO 8859-1 charset. * * @param string the string to convert. * @return string the converted string. */ function macRomanToIso($string) { return strtr($string, "\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\xd2\xd3\xd4\xd5", "\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\x22\x22\x27\x27"); } ?> ---- Manual Page -- http://www.php.net/manual/en/function.htmlentities.php Edit -- http://master.php.net/manage/user-notes.php?action=edit+40481 Delete -- http://master.php.net/manage/user-notes.php?action=delete+40481&report=yes Reject -- http://master.php.net/manage/user-notes.php?action=reject+40481&report=yes Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#66279) next »