By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
437,888 Members | 1,058 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 437,888 IT Pros & Developers. It's quick & easy.

PHP RegExp Help!

P: 9
I have the following regular expression which is stripping all unwanted characters before sending a variable to a url.

$url = preg_replace('~[^\\pL0-9_]+~u', '_', $url);

The problem is I would like to keep single quotation marks or encode them for the url so that I may retrieve them on the next page. The function above is currently getting rid of all single quotes.

I hacked this together and am not sure how to do this. Please Help!

Aaron
Feb 17 '08 #1
Share this Question
Share on Google+
3 Replies


Markus
Expert 5K+
P: 6,050
Just add a single quote (preceeded with a backslash) to the regex, then urlencode() the url.
[php]
$_url = "something'with' sing l e ' quotes in";
echo urlencode(preg_replace('~[^\\pL0-9_\']+~u', '_', $_url));
[/php]
Feb 17 '08 #2

P: 9
That did the trick. Thanks!
Feb 17 '08 #3

Markus
Expert 5K+
P: 6,050
That did the trick. Thanks!
No probs!
remember to urldecode() when you want to get the url params!
Feb 17 '08 #4

Post your reply

Sign in to post your reply or Sign up for a free account.