can I get the unicode value of a character or vise versa with php?

后端 未结 5 1332
北恋
北恋 2020-11-27 03:35

Is it possible to input a character and get the unicode value back? for example, i can put ⽇ in html to output \"⽇\", is it possible to give that character as an a

5条回答
  •  再見小時候
    2020-11-27 04:15

    Here's a more compact implementation of unichr/uniord based on pack:

    // code point to UTF-8 string
    function unichr($i) {
        return iconv('UCS-4LE', 'UTF-8', pack('V', $i));
    }
    
    // UTF-8 string to code point
    function uniord($s) {
        return unpack('V', iconv('UTF-8', 'UCS-4LE', $s))[1];
    }
    

提交回复
热议问题