Reputation: 12537
Given the address: 12345 West Palm Rd., #7B Daytona, FL
I am trying to remove the '.' character from 'Rd.' and the '#' character from '#7B'. However, I would like for these characters to be removed no matter what string is given.
Is there an easy way to do this?
I am familiar with strstr()
, but it seems like a complicated way to do what I am trying to do.
Upvotes: 2
Views: 245
Reputation: 5101
$str = preg_replace('/\./', '', $address);
$str = preg_replace('/#/', '', $str);
Upvotes: 1
Reputation: 352
Use the following php code:
$smt="12345 West Palm Rd., #7B Daytona, FL";
$smt=str_replace(".","",$smt);
$smt=str_replace("#","",$smt);
Upvotes: 1
Reputation: 3558
PHP has a convient string replace method for what you are trying to do.
$address = "12345 West Palm Rd., #7B Daytona, FL";
$characters = array('.','#',etc.);
$stripped = str_replace($characters, '', $address);
echo $stripped; // 12345 West Palm Rd, 7B Daytona, FL
Upvotes: 3