HTML Entity Decode

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



I found the following function at http://us.php.net/html_entity_decode. ; This looks exactly like what I need to filter out information in a text field that's been copied from Word.  The "endash" or "&#8211" is not being accepted and my processing page is halting.  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@xxxxxxx" 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  code2utf( <number> )  equals the character that is represented by the XML-entity  &#<number>;  (exceptions: #129, #141, #143, #144, #157).

To give an example, the function may be useful for creating a UTF-8-compatible html_entity_decode-function  or  determining the entry-position of UTF-8-characters in order to find the correct entity-replacement or similar.

    function code2utf($number)
    {
        if ($number < 0)
            return FALSE;
        
        if ($number < 128)
            return chr($number);
        
        // Removing / Replacing Windows Illegals Characters
        if ($number < 160)
        {
                if ($number==128) $number=8364;
            elseif ($number==129) $number=160; // (Rayo:) #129 using no relevant sign, thus, mapped to the saved-space #160
            elseif ($number==130) $number=8218;
            elseif ($number==131) $number=402;
            elseif ($number==132) $number=8222;
            elseif ($number==133) $number=8230;
            elseif ($number==134) $number=8224;
            elseif ($number==135) $number=8225;
            elseif ($number==136) $number=710;
            elseif ($number==137) $number=8240;
            elseif ($number==138) $number=352;
            elseif ($number==139) $number=8249;
            elseif ($number==140) $number=338;
            elseif ($number==141) $number=160; // (Rayo:) #129 using no relevant sign, thus, mapped to the saved-space #160
            elseif ($number==142) $number=381;
            elseif ($number==143) $number=160; // (Rayo:) #129 using no relevant sign, thus, mapped to the saved-space #160
            elseif ($number==144) $number=160; // (Rayo:) #129 using no relevant sign, thus, mapped to the saved-space #160
            elseif ($number==145) $number=8216;
            elseif ($number==146) $number=8217;
            elseif ($number==147) $number=8220;
            elseif ($number==148) $number=8221;
            elseif ($number==149) $number=8226;
            elseif ($number==150) $number=8211;
            elseif ($number==151) $number=8212;
            elseif ($number==152) $number=732;
            elseif ($number==153) $number=8482;
            elseif ($number==154) $number=353;
            elseif ($number==155) $number=8250;
            elseif ($number==156) $number=339;
            elseif ($number==157) $number=160; // (Rayo:) #129 using no relevant sign, thus, mapped to the saved-space #160
            elseif ($number==158) $number=382;
            elseif ($number==159) $number=376;
        } //if
        
        if ($number < 2048)
            return chr(($number >> 6) + 192) . chr(($number & 63) + 128);
        if ($number < 65536)
            return chr(($number >> 12) + 224) . chr((($number >> 6) & 63) + 128) . chr(($number & 63) + 128);
        if ($number < 2097152)
            return chr(($number >> 18) + 240) . chr((($number >> 12) & 63) + 128) . chr((($number >> 6) & 63) + 128) . chr(($number & 63) + 128);
        
        
        return FALSE;
    } //code2utf() 

Trish
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Patricia Van Buskirk
Florida State University, Office of Telecommunications
644 W. Call Street
Tallahassee, FL  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  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



[Index of Archives]     [PHP Home]     [PHP Users]     [Postgresql Discussion]     [Kernel Newbies]     [Postgresql]     [Yosemite News]

  Powered by Linux