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.

Advertisements

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 Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s




%d bloggers like this: