paulman888888 Posted June 1, 2008 Share Posted June 1, 2008 How can i remove all NONE letters and numbers. Please help <?php // Insert a row of information into the table "example" mysql_query("INSERT INTO example (name, score) VALUES('" . mysql_real_escape_string(substr($_GET['name'], 0, 13)) . "', '" . mysql_real_escape_string($_GET['score']) . "')") or die('Theres an error.# Please try again.#'); echo "Score Uploaded!#"; ?> Quote Link to comment Share on other sites More sharing options...
joquius Posted June 1, 2008 Share Posted June 1, 2008 What are you trying to remove these chars from? a string? $str = preg_replace ("/[^a-zA-Z0-9]/", "", $str); // this? Quote Link to comment Share on other sites More sharing options...
paulman888888 Posted June 1, 2008 Author Share Posted June 1, 2008 i have my $_name variable and i would like all NONE letters and numbers to be removed. I thought of this but i havent finshed it because i dont know how. <?php $thename=remove_none_letters_and_numbers($_get['name'])// the part i added but dont know how to make work // Insert a row of information into the table "example" mysql_query("INSERT INTO example (name, score) VALUES('" . mysql_real_escape_string(substr($thename, 0, 13)) . "', '" . mysql_real_escape_string($_GET['score']) . "')") or die('Theres an error.# Please try again.#'); echo "Score Uploaded!#"; ?> please help Quote Link to comment Share on other sites More sharing options...
trq Posted June 1, 2008 Share Posted June 1, 2008 See the previous reply. Quote Link to comment Share on other sites More sharing options...
paulman888888 Posted June 1, 2008 Author Share Posted June 1, 2008 where do i put it? Quote Link to comment Share on other sites More sharing options...
joquius Posted June 1, 2008 Share Posted June 1, 2008 Your code: $thename=remove_none_letters_and_numbers($_get['name'])// the part i added but dont know how to make work turns into: $thename = preg_replace ("/[^a-zA-Z0-9]/", "", $_GET['name']); or if you like function clearInvalidChars ($str) { return preg_replace ("/[^a-zA-Z0-9]/", "", $str); } $thename = clearInvalidChars ($_GET['name']); Quote Link to comment Share on other sites More sharing options...
paulman888888 Posted June 1, 2008 Author Share Posted June 1, 2008 thankyou all Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.