tags:

views:

55

answers:

2

I'm using the substr() function to limit the characters in strings. but sometimes, the output text contains some obscure characters and Question marks etc...

the text which is "substred" is already UTF8 encoded, and NOT in html entities to make like this problem.

Thanks

+9  A: 

Use mb_substr for multibyte character encodings like UTF-8. substr just counts bytes while mb_substr counts characters.

Gumbo
Thanks, worked :D
David
+1  A: 

The reason is that you use UTF-8, it's multibyte encoding,and substr() works with singlebyte only! htmlentities() doesn't matter.

You SHOULD use mb_substr() http://php.net/manual/en/function.mb-substr.php and other multibyte functions

Dan