Re: String formatting using preg_replace
| From: | Jason k Larson | Date: | Tue, 13 May 2003 14:55:13 +0000 |
| Subject: | Re: String formatting using preg_replace | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-147445@lists.php.net to get a copy of this message | ||
You are close ... here is an example for your current purposes.
$compname = 'Joe`s Garage Inc.';
$trim1 = trim($compname);
$cust_dir = preg_replace("/[`0-9. ]*/","",$trim1);
echo $cust_dir;
This will return: JoesGarageInc
If you want: joesgarageinc
You'll need to do something like this:
$cust_dir = strtolower(preg_replace("/[`0-9. ]*/","",$trim1));
HTH
--
Ritter
aka: Jason k Larson
Chris Blake wrote:
Greetings learned PHP(eople), Objective : Strip out all occurrences of the following from a string : /?<>,.;':"`!@#$%^&*()1234567890-+=\| ....and replace them with nothing Code : $compname = 'Joe`s Garage Inc.'; $trim1 = trim($compname); $cust_dir = preg_replace("/`1234567890 /","",$trim1); echo $cust_dir ; Problem : Not working....the string is getting returned as it was declared in $compname without any formatting/stripping It should read "joesgarageinc" I have read about preg_replace but I`m seriously confused by the format of the stuff you want to strip away... Am I right in assuming that str_replace can only replace one character, i.e. you can`t specify many things to replace Also, my trusty tome "PHP & MySQL Web Development" only references preg_replace once, and then they only use a simple example of stripping away one character.. Help please, much appreciated.