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:
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
Comments
Post a Comment