PDA

View Full Version : filter/remove metacharacter from a string


ultra
11-07-2006, 12:31 PM
Hi,
How can I filter a string by removing characters others than listed below;
a-z,
A-Z,
0-9,
( ) space,
(_) underscore
(-) minus sign

example
'is this $100?' would become 'is this 100'

Vege
11-07-2006, 01:24 PM
<?php

$k = "s<>/\email";
$k2 = preg_replace('/[^a-z0-9_-]+/i','', $k);
echo $k2;
?>

Something like this?

ultra
11-07-2006, 05:14 PM
exactly... thank you so much