Folks,
I have a string that *could* contain any character - I want it to call a
function that will allow me to pass the variable, and then return it cleaned
of anything except alphanumeric, dots, dashes and commas... How would I do
this? I have a feeling preg_replace is what I need to use but regular
expressions have always been over my head. I do know the syntax though
(taken from a previous posting made some weeks ago) that I've been trying to
play with - the previous post had
check to see if a forename field entry is composed only of letters
if(!preg_match( "/^[a-zA-Z]+$/",$_POST["Nforename"]))
{
// invalid form entry. go back to form
}
with /^[0-9]+$/ - only digits 0 - 9 allowed
with /^[a-zA-Z\s]+$/ - letters and spaces
with /^[a-zA-Z0-9\.]$/ - letters, numbers and periods
I've been trying something like
$myString="abc' de!789()";
$myCleanedStrin g=preg_replace( "/^[a-zA-Z0-9\.]$/", "/^[a-zA-Z0-9\.]$/",
$myString);
(I thought it would search characters listed in the frist arguement and
replace them with characters in the second arguement and ignore everything
else - but I was wrong).
Can someone help me here?
Thanks!
Comment