tags:

views:

316

answers:

2

When I use substr() I get a strange character at the end

$articleText = substr($articleText,0,500);

I have an output of 500 chars and � <--

How can iIfix this? Is it an encoding problem? My language is Greek.

+9  A: 

substr is counting using bytes, and not characters.

greek probably means you are using some multi-byte encoding, like UTF-8 -- and counting per bytes is not quite good for those.

Maybe using mb_substr could help, here : the mb_* functions have been created specifically for multi-byte encodings.

Pascal MARTIN
+3  A: 

Looks like you're slicing a unicode character in half there. Use mb_substr instead for unicode-safe string slicing.

deceze