Substr eating chars

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
satikas
Forum Newbie
Posts: 19
Joined: Sat Mar 28, 2009 9:14 am

Substr eating chars

Post 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.
cpetercarter
Forum Contributor
Posts: 474
Joined: Sat Jul 25, 2009 2:00 am

Re: Substr eating chars

Post by cpetercarter »

Have a look at php multibyte functions = http://www.php.net/manual/en/intro.mbstring.php
satikas
Forum Newbie
Posts: 19
Joined: Sat Mar 28, 2009 9:14 am

Re: Substr eating chars

Post by satikas »

Not helping, but thanks.

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

Doesnt work either.
Post Reply