Jump to content

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

:D wow thanks for the quick reply... I have tried this and get a blank screen: :shrug:

 

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

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


[\code]

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");

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.