php regex to alow slash in string -


here regex exclude special character other allowing few (-,%,:,@). want allow / getting issue

 return preg_replace('/[^a-za-z0-9_ %\[\]\.\(\)%:@&-]/s', '', $string); 

this works fine listed special character, but

 return preg_replace('/[^a-za-z0-9_ %\[\]\.\(\)%\\:&-]/s', '', $string);  

does not filter l chracter to.

here link test:

http://ideone.com/wxr0ka

where not allow \\ in url. want dispaly url usual

you're making mistake in entering http:// http:\\ regex needs include / in exclusion list. should work:

function clean($string) {    // replaces spaces hyphens.    $string = str_replace(' ', '-', $string);    // removes special chars.    return preg_replace('~[^\w %\[\].()%\\:@&/-]~', '', $string); }  $d =  clean("this http://nice readlly n'ice 'test for@me to") ; echo $d; // this-was-http://nice-readlly-nice-test-for@me-to 

working demo


Comments

Popular posts from this blog

jQuery Mobile app not scrolling in Firefox -

c++ - How to add Crypto++ library to Qt project -

how to receive file in java(servlet/jsp) -