I'm using the substr()
function to limit the characters in strings. but sometimes, the output text contains some obscure characters and Question marks etc...
the text which is "substred" is already UTF8 encoded, and NOT in html entities to make like this problem.
Thanks
substr in PHP is a built-in function used to extract a part of the given string. The function returns the substring specified by the start and length parameter. It is supported by PHP 4 and above. Let us see how we can use substr() to cut a portion of the string.
You can replace a substring using replace() method in Java. The String class provides the overloaded version of the replace() method, but you need to use the replace(CharSequence target, CharSequence replacement).
You can use the substr function like this: echo substr($myStr, 0, 5); The second argument to substr is from what position what you want to start and third arguments is for how many characters you want to return.
To get the first n characters from a string, we can use the built-in substr() function in PHP. Here is an example, that gets the first 3 characters from a following string. <? php echo substr("Ok-Google", 0, 3); ?>
Because you are cutting your characters into half.
Use mb_substr
for multibyte character encodings like UTF-8. substr
just counts bytes while mb_substr
counts characters.
The reason is that you use UTF-8, it's multibyte encoding,and substr() works with singlebyte only! htmlentities() doesn't matter.
You SHOULD use mb_substr() http://php.net/manual/en/function.mb-substr.php and other multibyte functions
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With