homepage Welcome to WebmasterWorld Guest from 23.23.22.200
register, free tools, login, search, subscribe, help, library, announcements, recent posts, open posts,
Subscribe to WebmasterWorld
Visit PubCon.com
Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
Forum Library, Charter, Moderators: coopster & jatar k

PHP Server Side Scripting Forum

    
Preg replace help?
BlackRaven




msg:4242109
 5:59 am on Dec 14, 2010 (gmt 0)

Hi,
i need help with my preg_replace, basically i am trying to replace everything except RFC 3986 valid chars


$User_URL=preg_replace('/[^A-Z, a-z, 0-9, -, ., _, ~, :, /, ?, #, [, ], @, !, $, &, ', (, ), *, +, ,, ;,=,%]/', '', $User_URL);



Thanks

 

astupidname




msg:4242141
 8:37 am on Dec 14, 2010 (gmt 0)

You need to escape special characters which have meaning within regular expressions, also you are not actually building an array here, so no need to seperate each character with a comma. So I think this should cover it:

$User_URL=preg_replace('/[^A-Za-z0-9\-\._\~\:\/\?#\[\]@\!\$&\'\(\)\*\+,;\=%]/', '', $User_URL);

Though I would have to ask, won't the replacement butcher the url? Would you not be able to just use rawurlencode() [php.net] or urlencode() [php.net] instead?

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved