mbstring

php mbstring扩展库处理中文字符

Deadly 提交于 2020-04-07 12:31:27
mbstring(Multibyte String 多字节字符串) 以前处理字符都是通过 substr strlen,但是现在要求精确多国语言并存就意味着多字节,PHP内置的字符串长度函数strlen无法正确处理中文字符串,它得到的只是字符串所占的字节数。对于GB2312的中文编码,strlen得到的值是汉字个数的2倍,而对于UTF-8编码的中文,就是1~3倍的差异了。 采用PHP字符串mbstring可以较好地解决这个问题。mb_strlen的用法和strlen类似,只不过它有第二个可选参数用于指定字符编码。例如得到UTF-8的字符串$str长度,可以用mb_strlen($str,’UTF-8′)。如果省略第二个参数,则会使用PHP的内部编码。内部编码可以通过mb_internal_encoding()函数得到,设置有两种方式: 1. 在php.ini中设置mbstring.internal_encoding = UTF-8 2. 调用mb_internal_encoding(”GBK”) 除了PHP字符串mbstring,还有很多切割函数,其中mb_substr是按字来切分字符,而mb_strcut是按字节来切分字符,但是都不会产生半个字符的现象。而且从函数切割对长度的作用也不同,mb_strcut的切割条件是小于strlen, mb_substr是等于strlen

PHP mbstring doesn't work with Apache on Windows

丶灬走出姿态 提交于 2020-01-23 03:50:27
问题 I have to get PHP 5.4 (32 bit, TS) with mbstring running with Apache 2.4 (32 bit) on Windows. In my httpd.conf I set this: PHPIniDir "c:/php54" LoadModule php5_module "c:/php54/php5apache2_4.dll" AddHandler application/x-httpd-php .php And in my php.ini: extension_dir = "ext" ... extension=php_mbstring.dll Now, when I execute php -m it correctly says that mbstring is loaded: ... libxml mbstring mcrypt ... And php -i spits out a section about mbstring: mbstring Multibyte Support => enabled

Mbstring extension installation on godaddy server

送分小仙女□ 提交于 2020-01-07 03:42:08
问题 Call to undefined function mb_convert_encoding(). How to install mbstring extension installation on godaddy server? 回答1: I have found the solution. We need to complete the following steps: 1.Login to your server WHM as root 2.Search EasyApache or go to Software menu after that EasyApache 3. you can see there are some profile. click on customize profile default profile. 4. click on continue to second step 5. On “Step 2,” click on “Exhaustive Options” 6. Under PHP, check the checkbox for

Mbstring extension installation on godaddy server

眉间皱痕 提交于 2020-01-07 03:41:24
问题 Call to undefined function mb_convert_encoding(). How to install mbstring extension installation on godaddy server? 回答1: I have found the solution. We need to complete the following steps: 1.Login to your server WHM as root 2.Search EasyApache or go to Software menu after that EasyApache 3. you can see there are some profile. click on customize profile default profile. 4. click on continue to second step 5. On “Step 2,” click on “Exhaustive Options” 6. Under PHP, check the checkbox for

PHP mb_substr() not working correctly?

允我心安 提交于 2020-01-01 07:33:07
问题 This code print mb_substr('éxxx', 0, 1); prints an empty space :( It is supposed to print the first character, é . This seems to work however: print mb_substr('éxxx', 0, 2); But it's not right, because (0, 2) means 2 characters... 回答1: Try passing the encoding parameter to mb_substr, as such: print mb_substr('éxxx', 0, 1, 'utf-8'); The encoding is never detected automatically. 回答2: In practice I've found that, in some systems, multi-byte functions default to ISO-8859-1 for internal encoding.

Replacing invalid UTF-8 characters by question marks, mbstring.substitute_character seems ignored

最后都变了- 提交于 2019-12-28 03:09:10
问题 I would like to replace invalid UTF-8 chars with quotation marks (PHP 5.3.5). So far I have this solution, but invalid characters are removed, instead of being replaced by '?'. function replace_invalid_utf8($str) { return mb_convert_encoding($str, 'UTF-8', 'UTF-8'); } echo mb_substitute_character()."\n"; echo replace_invalid_utf8('éééaaaàààeeé')."\n"; echo replace_invalid_utf8('eeeaaaaaaeeé')."\n"; Should output: 63 // ASCII code for '?' character ???aaa???eé // or ??aa??eé eeeaaaaaaeeé But

call to undefined function mb_strimwidth

强颜欢笑 提交于 2019-12-21 09:16:45
问题 Months ago I made a short code that uses mb_strimwidth() to exactly fit some text into a table cell, putting dots at the end of a truncated string. Now, after some times, I tried to execute that same code and it went out with this error: Fatal error: Call to undefined function mb_strimwidth() in ... I tried to find the mbstring.php file, and when I found the mb_strimwidth() function, I discovered that it is not implemented anymore. How is that possible? But my main question is: how can I get

iconv or mbstring?

北战南征 提交于 2019-12-21 07:36:34
问题 Which multibyte-handling library should I use : iconv or mbstring ? After some Googling I didn't find enough arguments to convince me to use one particularly, and I could not get any benchmark (and I'm too lazy do create one :-p). After all maybe this choice doesn't really matters ? Thanks for any piece of advice. 回答1: I tend to use a combination of both - depending on my needs. I use iconv to convert from one charset to another, but mbstring for simpler operations like mb_strtoupper() and mb

openSUSE phpmyadmin Error: The mbstring extension is missing

拥有回忆 提交于 2019-12-20 05:53:07
问题 phpMyAdmin - Error The mbstring extension is missing. Please check your PHP configuration. I hava installed php-mbstring and php-gettext, my php version is php7. And I installed php and phpmyadmin through zypper. 回答1: install mbstring and restart your apache: sudo apt-get install php-mbstring sudo service apache restart then remove ; from your php.ini file: ;extension=php_mbstring.dll to extension=php_mbstring.dll If it still doesn't work..remove your php setup, without removing the databases