HTML Entity Decode
am 26.03.2008 17:23:20 von pvanbuskirkI found the following function at =
http://us.php.net/html_entity_decode.=A0 This looks exactly like what I =
need to filter out information in a text field that's been copied from =
Word.=A0 The "endash" or "–" is not being accepted and my =
processing page is halting.=A0 My question to you is where in my page do =
I call this function and how .. where do I get "$number"?
------------------------------------------------------------ -------------=
-------
In answer to "laurynas dot butkus at gmail dot com" and "romans@void.lv" =
and their great code2utf-function I added the functionality for entries =
between [128, 160[ that are not ASCii, but equal for all major western =
encodings like ISO8859-X and UTF-8 that has been mentioned before.
Now, the following function should in fact convert any number =
(table-entry) into an UTF-8-character. Thus, the return-value=A0 =
code2utf(
XML-entity=A0
To give an example, the function may be useful for creating a =
UTF-8-compatible html_entity_decode-function=A0 or=A0 determining the =
entry-position of UTF-8-characters in order to find the correct =
entity-replacement or similar.
=A0 function code2utf($number)
=A0 {
=A0 if ($number < 0)
=A0 =A0 =A0 return FALSE;
=A0 =20
=A0 if ($number < 128)
=A0 =A0 =A0 return chr($number);
=A0 =20
=A0 // Removing / Replacing Windows Illegals Characters
=A0 if ($number < 160)
=A0 {
=A0 =A0 =A0 =A0 =A0 if ($number==128) $number=3D8364;
=A0 =A0 =A0 elseif ($number==129) $number=3D160; // =
(Rayo:) #129 using no relevant sign, thus, mapped to the saved-space =
#160
=A0 =A0 =A0 elseif ($number==130) $number=3D8218;
=A0 =A0 =A0 elseif ($number==131) $number=3D402;
=A0 =A0 =A0 elseif ($number==132) $number=3D8222;
=A0 =A0 =A0 elseif ($number==133) $number=3D8230;
=A0 =A0 =A0 elseif ($number==134) $number=3D8224;
=A0 =A0 =A0 elseif ($number==135) $number=3D8225;
=A0 =A0 =A0 elseif ($number==136) $number=3D710;
=A0 =A0 =A0 elseif ($number==137) $number=3D8240;
=A0 =A0 =A0 elseif ($number==138) $number=3D352;
=A0 =A0 =A0 elseif ($number==139) $number=3D8249;
=A0 =A0 =A0 elseif ($number==140) $number=3D338;
=A0 =A0 =A0 elseif ($number==141) $number=3D160; // =
(Rayo:) #129 using no relevant sign, thus, mapped to the saved-space =
#160
=A0 =A0 =A0 elseif ($number==142) $number=3D381;
=A0 =A0 =A0 elseif ($number==143) $number=3D160; // =
(Rayo:) #129 using no relevant sign, thus, mapped to the saved-space =
#160
=A0 =A0 =A0 elseif ($number==144) $number=3D160; // =
(Rayo:) #129 using no relevant sign, thus, mapped to the saved-space =
#160
=A0 =A0 =A0 elseif ($number==145) $number=3D8216;
=A0 =A0 =A0 elseif ($number==146) $number=3D8217;
=A0 =A0 =A0 elseif ($number==147) $number=3D8220;
=A0 =A0 =A0 elseif ($number==148) $number=3D8221;
=A0 =A0 =A0 elseif ($number==149) $number=3D8226;
=A0 =A0 =A0 elseif ($number==150) $number=3D8211;
=A0 =A0 =A0 elseif ($number==151) $number=3D8212;
=A0 =A0 =A0 elseif ($number==152) $number=3D732;
=A0 =A0 =A0 elseif ($number==153) $number=3D8482;
=A0 =A0 =A0 elseif ($number==154) $number=3D353;
=A0 =A0 =A0 elseif ($number==155) $number=3D8250;
=A0 =A0 =A0 elseif ($number==156) $number=3D339;
=A0 =A0 =A0 elseif ($number==157) $number=3D160; // =
(Rayo:) #129 using no relevant sign, thus, mapped to the saved-space =
#160
=A0 =A0 =A0 elseif ($number==158) $number=3D382;
=A0 =A0 =A0 elseif ($number==159) $number=3D376;
=A0 } //if
=A0 =20
=A0 if ($number < 2048)
=A0 =A0 =A0 return chr(($number >> 6) + 192) . =
chr(($number & 63) + 128);
=A0 if ($number < 65536)
=A0 =A0 =A0 return chr(($number >> 12) + 224) . =
chr((($number >> 6) & 63) + 128) . chr(($number & 63) + 128);
=A0 if ($number < 2097152)
=A0 =A0 =A0 return chr(($number >> 18) + 240) . =
chr((($number >> 12) & 63) + 128) . chr((($number >> 6) & 63) + 128) . =
chr(($number & 63) + 128);
=A0 =20
=A0 =20
=A0 return FALSE;
=A0 } //code2utf()=20
Trish
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Patricia Van Buskirk
Florida State University, Office of Telecommunications
644 W. Call Street
Tallahassee, FL=A0 32306-1120
(850) 644-9247
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
"Life may not be the party we hoped for, but while we're still here we =
may as well dance."'' Life may not be the party we hoped for, but while =
we're still here we may as well dance.' ' Life may not be the party we =
hoped for, but while we're still here we may as well dance.'
Trish
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Patricia Van Buskirk
Florida State University, Office of Telecommunications
644 W. Call Street
Tallahassee, FL=A0 32306-1120
(850) 644-9247
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
"Life may not be the party we hoped for, but while we're still here we =
may as well dance."'' Life may not be the party we hoped for, but while =
we're still here we may as well dance.' ' Life may not be the party we =
hoped for, but while we're still here we may as well dance.'
--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php