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!#"; ?> Link to comment https://forums.phpfreaks.com/topic/108227-solved-quick-question/ 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? Link to comment https://forums.phpfreaks.com/topic/108227-solved-quick-question/#findComment-554749 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 Link to comment https://forums.phpfreaks.com/topic/108227-solved-quick-question/#findComment-554755 Share on other sites More sharing options...
trq Posted June 1, 2008 Share Posted June 1, 2008 See the previous reply. Link to comment https://forums.phpfreaks.com/topic/108227-solved-quick-question/#findComment-554759 Share on other sites More sharing options...
paulman888888 Posted June 1, 2008 Author Share Posted June 1, 2008 where do i put it? Link to comment https://forums.phpfreaks.com/topic/108227-solved-quick-question/#findComment-554764 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']); Link to comment https://forums.phpfreaks.com/topic/108227-solved-quick-question/#findComment-554767 Share on other sites More sharing options...
paulman888888 Posted June 1, 2008 Author Share Posted June 1, 2008 thankyou all Link to comment https://forums.phpfreaks.com/topic/108227-solved-quick-question/#findComment-554777 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.