Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Difference between mb_substr and substr

Will it make any difference or impact on my result, if I use substr() instead of mb_substr() function?

As my server does not have support for mb_ functions, I have to replace it with substr()

like image 739
Poonam Bhatt Avatar asked Oct 29 '12 11:10

Poonam Bhatt


People also ask

What is the purpose of substr () function?

The SUBSTR function acts on a character string expression or a bit string expression. The type of the result is a VARCHAR in the first case and VARCHAR FOR BIT DATA in the second case. The length of the result is the maximum length of the source type.

How does Substr work PHP?

The substr() is a built-in function in PHP that is used to extract a part of string. Parameters: The substr() function allows 3 parameters or arguments out of which two are mandatory and one is optional. start_position: This refers to the position of the original string from where the part needs to be extracted.

Is substring in string PHP?

You can use the PHP strpos() function to check whether a string contains a specific word or not. The strpos() function returns the position of the first occurrence of a substring in a string. If the substring is not found it returns false .


1 Answers

If you have utf-8 encoding use mb_substr

Example :

echo substr("hi mémé", 0 , 5); // will print hi m� echo mb_substr("hi mémé", 0 , 5); // will print hi mé 
like image 90
Saad Achemlal Avatar answered Oct 10 '22 18:10

Saad Achemlal