strlen vs mb_strlen function in php

7 06 2009

I wrote a simple class in php called cut html string . This class with cut the html string without considering html tags but the output will have the html tags as it is. Here I used strlen function to find the length of string. This function return the number of bytes of the string. If string has some utf8 special characters then it returns wrong value, because those special characters will take more bytes. I want to find the number of characters in the string. mb_strlen function returns the number of characters in string. A multi-byte character is counted as 1. I prefer to use mb_strlen function to find the character count of a string.


Actions

Information

4 responses

9 06 2009
Yogesh

Very useful indeed. Nice work.

5 07 2009
bas

Problem with national letter. Function stops.

5 07 2009
Prajwala

Can you give one example?

21 12 2009
thanks

very useful for non us-acii implementations. Thank you.

Leave a comment