Jump to content

[SOLVED] Quick question


paulman888888

Recommended Posts

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

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

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']);

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.