Good day! I have a cyrrylic texts in mysql. I need it to be cutted to 130 symbols everytime after sql query on a cicle. But. Function does unequal strings, even more it returns less than 130, near 70-80 symbols. What is the mess there? Result is here marketsite.byethost12.com
Are you allowing for empty spaces ? Example : "1 2 3 4 5" = 9 characters If you wanted to show 1 2 3 $str = substr($str, 0, 5); // you would have to count 5 characters
Yes i have count all places in text including spaces and it is 72-90 not 130 as is in script substr($text, 0, 130); You can see on site
It's working correctly...... kind of......... Simple explanation: The characters you are using are part of an extended character set (UTF-8) meaning that they will be represented by more than 1 byte each. As the core function process it per byte, you are getting less "characters" back because of it....... You might want to look at mb_substr instead. http://uk.php.net/manual/en/function.mb-substr.php
I have remake this code from substr($text, 0, 130); to mb_substr($text, 0, 130, 'utf8'); It becomes a little similar by length but far to equal
What happens if you do this before the mb_substr? mb_internal_encoding('UTF-8'); PHP: Failing that, you might want to also try mb-strcut; its similar but there are slight differences with how multi-byte characters are handled. http://uk.php.net/manual/en/function.mb-strcut.php
It outputs cipher 1 everywhere instead of text after i insert mb_internal_encoding('UTF-8'); marketsite.byethost12.com
It fine for me on a test server; What is the mb settings on the server you are using by default? Are you checking that the strings you are trying to shorten are actually more than 130 characters? Also, You might want to take a look at some of the pointers and problems described here which is pretty thorough; http://www.phpwact.org/php/i18n/charsets