String formatting using preg_replace
| From: | Chris Blake | Date: | Tue, 13 May 2003 14:39:46 +0000 |
| Subject: | String formatting using preg_replace | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-147440@lists.php.net to get a copy of this message | ||
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.
--
Chris Blake
Office : (011) 782-0840
Cell : 083 985 0379
"Remember, Information is not knowledge; Knowledge is not Wisdom;
Wisdom is not truth; Truth is not beauty; Beauty is not love;
Love is not music; Music is the best." -- Frank Zappa