Home > Backend Development > PHP Tutorial > 大小写转换 - php怎么让英文字符串都变成小写

大小写转换 - php怎么让英文字符串都变成小写

WBOY
Release: 2016-06-06 20:40:26
Original
1306 people have browsed it

系统里面有一大堆数据是大小写混编的随机字符串,现在我想批量转换成小写形式的,最好的办法是什么?

回复内容:

系统里面有一大堆数据是大小写混编的随机字符串,现在我想批量转换成小写形式的,最好的办法是什么?

strtolower()在有些环境里传入带有中文的字符串是会出问题的,建议用下面的替代方案:

<code>/**
 * 转换大写为小写字母(某些系统下自带的strtolower在转换含中文的串时出错)
 * @param string $string
 */
public static function str_tolower($string){
    return strtr($string, 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz');
}
</code>
Copy after login

strtolower()函数

<code><?php echo strtolower("Hello WORLD.");
?>
</code>
Copy after login

文档

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template