Page 1 of 1
preg_replace help for a single quote
Posted: Tue Jun 12, 2007 7:15 am
by tecktalkcm0391
How can I make this preg_replace be only letters and an single quote ( ' )
Code: Select all
$cat = preg_replace('/[^a-z]/i', '',url_decode($_GET['cat']));
Thanks!
Posted: Tue Jun 12, 2007 7:34 am
by Oren
I assume you meant anything other than letters and single quotes (because of the
^ you have in your code).
Posted: Tue Jun 12, 2007 7:41 am
by tecktalkcm0391
No, I wanted only letters and a single quote. I'm not good a this preg_replace and match stuff and I got it on a web site.
Posted: Tue Jun 12, 2007 7:49 am
by Oren
Well,
^ inside
[] means "anything but what's inside the []".
If what you want it only letters and single quotes then try this:
Posted: Tue Jun 12, 2007 8:41 am
by tecktalkcm0391
Oren wrote:Well,
^ inside
[] means "anything but what's inside the []".
If what you want it only letters and single quotes then try this:
Thanks it worked!
Now thats lead me to another problem I didn't see coming. I have a mod_rewrite script of:
Code: Select all
RewriteRule browse/([A-Za-z']+)$ /browser.php?cat=$1 [NC]
RewriteRule browse/([A-Za-z']+)/([0-9]+)$ /browser.php?cat=$1&p=$2 [NC]
Which allows the letters and single quote, but when the URL comes of for /browse/Chris' Items it comes up /browse/Chris'%20Items.
How can I fix that to allow the %20
Posted: Tue Jun 12, 2007 10:17 am
by Oren
Well, you will need to allow digits and %'s too: