Asked  9 Months ago    Answers:  5   Viewed   44 times

I have a PHP file with one simple echo function:

echo '????????????';

but when I access that page i get this:

????????????

Can someone help me? I also have my page encoding set to UTF-8, and I know it, because all of the browsers i used said so. I also do this before the echo function:

mb_internal_encoding('UTF-8');

What does this do? Does it help me? All I need is to be able to echo a static Japanese string.

Thanks!

 Answers

11

I got it. I just had to set the mbstring extension settings to handle internal strings in UTF-8. Thas extension is standard with my build of PHP 5.3.0.

Wednesday, March 31, 2021
 
Hat
answered 9 Months ago
Hat
43

The core PHP string functions all assume 1 character = 1 byte. They have no concept of different encodings. To figure out how many characters are in a UTF-8 string (not how many bytes), use the mb_strlen equivalent and tell it what encoding the string is in:

echo mb_strlen('????', 'UTF-8');
Wednesday, March 31, 2021
 
CMOS
answered 9 Months ago
47

It sure does look to me that id_key is being passed by reference.

Some of those PDO libraries are coded in C. It's quite possible that in the innards the variables get corrupted there.

TBF you're passing a string as an argument that expects a numeric value, so from the standpoint of the functions you're using, the new value is the same as the old value (most text strings not containing digits = 0).

Friday, May 28, 2021
 
bumperbox
answered 7 Months ago
46

Try passing the encoding parameter to mb_substr, as such:

print mb_substr('éxxx', 0, 1, 'utf-8');

The encoding is never detected automatically.

Saturday, May 29, 2021
 
keisar
answered 7 Months ago
56

You should change your file encoding to UTF-8 and set the header on the website to UTF-8.

<meta http-equiv="content-type" content="text/html; charset=UTF-8">

in HTML5 you should use:

<meta charset="utf-8" /> 

or in php

header('content-type: text/html; charset=utf-8');
Sunday, August 22, 2021
 
Scheff's Cat
answered 4 Months ago
Only authorized users can answer the question. Please sign in first, or register a free account.
Not the answer you're looking for? Browse other questions tagged :
 
Share