Page 1 of 1

Substr eating chars

Posted: Tue Dec 22, 2009 3:56 pm
by satikas
Hi, my substr function is eating 2 byte (i think) chars such as ö,ä,ü,õ which eventually leads to having "?" in the values.

For example:

$roflmao1 = "somerandomtext";
$roflmao2 = "äöõüäöõüäöäöõü";

if(strlen("$roflmao1") > 10){ $roflmao1 = substr($roflmao1, 0, 10) . '...'; } RESULTS: somerandom...

if(strlen("$roflmao2") > 10){$roflmao2 = substr($roflmao2, 0, 10) . '...';} RESULTS: äöõüäöõüä?...

Could anyone provide a solution for this.
Thank you.

Re: Substr eating chars

Posted: Tue Dec 22, 2009 6:05 pm
by cpetercarter
Have a look at php multibyte functions = http://www.php.net/manual/en/intro.mbstring.php

Re: Substr eating chars

Posted: Wed Dec 23, 2009 4:56 am
by satikas
Not helping, but thanks.

if(mb_strlen($roflmao2) > 20){ $roflmao2 = mb_substr($roflmao2, 0, 20) . '...'; }

Doesnt work either.