[英]Remove everything except letters from PHP string
How can I remove everything from a string apart from letters? 除了字母之外,如何从字符串中删除所有内容? I have an input field for first names. 我有一个名字的输入字段。
In PHP, you can use (as suggested by @rczajka and @mario): 在PHP中,您可以使用(如@rczajka和@mario所建议的):
preg_replace('/\PL/u', '', $str)
Working Example: http://codepad.viper-7.com/V78skl 工作示例: http : //codepad.viper-7.com/V78skl
You may want to checkout this Tutorial for regex 您可能想要查看此教程以获取正则表达式
$new_string = preg_replace('/[^a-z]/i','',$old_string);
$new_string = ereg_replace("[^A-Za-z]", "", $string );
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.