Home > Software design >  Taking only letters out of string is not working in PHP
Taking only letters out of string is not working in PHP

Time:07-03

I have a database table which contains some application numbers. I want to take only letters out of its for example, I did the following:

$post_content="BGCG0";
$only_text =preg_replace("/[^a-zA-Z0-9] /", "", $post_content);
echo $only_text;

However it doesn't do it. Can anyone please tell me how to accomplish this?

CodePudding user response:

You're allowing digits in your regex. Remove the 0-9 part from it and you should be OK:

$only_text = preg_replace("/[^a-zA-Z] /", "", $post_content);
# Here -----------------------------^
  • Related