Remove everything except the letters from the PHP string.

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

+6
source share
3 answers

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 can check this tutorial for regular expression.

+17
source
 $new_string = preg_replace('/[^az]/i','',$old_string); 
+8
source
 $new_string = ereg_replace("[^A-Za-z]", "", $string ); 
-1
source

Source: https://habr.com/ru/post/896359/


All Articles