Remove everything except letters from PHP string

2020-02-01 19:03发布

How can I remove everything from a string apart from letters? I have an input field for first names.

3条回答
We Are One
2楼-- · 2020-02-01 19:05

In PHP, you can use (as suggested by @rczajka and @mario):

preg_replace('/\PL/u', '', $str)

Working Example: http://codepad.viper-7.com/V78skl

You may want to checkout this Tutorial for regex

查看更多
聊天终结者
3楼-- · 2020-02-01 19:14
$new_string = preg_replace('/[^a-z]/i','',$old_string);
查看更多
该账号已被封号
4楼-- · 2020-02-01 19:20
$new_string = ereg_replace("[^A-Za-z]", "", $string );
查看更多
登录 后发表回答