Remove everything except letters from PHP string

后端 未结 3 681
傲寒
傲寒 2020-12-07 01:10

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

相关标签:
3条回答
  • 2020-12-07 01:56
    $new_string = ereg_replace("[^A-Za-z]", "", $string );
    
    0 讨论(0)
  • 2020-12-07 02:01
    $new_string = preg_replace('/[^a-z]/i','',$old_string);
    
    0 讨论(0)
  • 2020-12-07 02:04

    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

    0 讨论(0)
提交回复
热议问题