Jump to content

PHP funtion to remove non a to z


nish.patel

Recommended Posts

Hi all,

 

I am a newbie so please go gentle... I am trying to get a function to work for my application i have been learning PHP by watch Kevin Skoglund's videos etc but I cannot find a solution for this. I have been googling frantically but no joy hence you guys are my only option now. Below is the snippet of code that I have tried to get it to work but no joy can anyone show me how its done thanks...

 

what i am trying to do is to input "BA'3Ndf$%^A&*(nN)A" and trying to return BANANA in PHP:

 

function remove_nonAtoZ($input) {
$input = preg_replace('#[^\d]#', $input);

$input = "BA'3Ndf$%^A&*(nN)A";
$output = "BANANA";
return $output;
}

 

Link to comment
https://forums.phpfreaks.com/topic/182149-php-funtion-to-remove-non-a-to-z/
Share on other sites

You should do some research about how functions work and how to utilize them, check out the manual. The way to use this function would be like so:

 

function remove_nonAtoZ($input) {
return preg_replace('~[^A-Z]~', '', $input);
}

echo remove_nonAtoZ("BA'3Ndf$%^A&*(nN)A");

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.