Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
335 views
in Technique[技术] by (71.8m points)

php - ord() doesn't work with utf-8

according to ISO 8859-1

€ Symbol has decimal value 128

My default php script encoding is

echo mb_internal_encoding(); //ISO-8859-1

So now as PHP

echo chr(128);  //Output exactly what i want '€'

But

echo ord('€');  //opposite it returns 226, it should be 128

why it is so?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

It is only for 2018's PHP v7.2.0+.

mb_ord()

Now you can use mb_ord(). Example echo mb_ord('€','UTF-8');

See also mb_chr(), to get the UTF-8 representation of a decimal code.
Example echo mb_chr(2048,'UTF-8');.


The best practice is to be universal, save all your PHP scripts as UTF-8 (see @deceze).


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...