mysql php搜索表单-希望在选择查询之前从用户输入中删除特殊字符

mysql php搜索表单-希望在选择查询之前从用户输入中删除特殊字符,php,mysql,regex,forms,search,Php,Mysql,Regex,Forms,Search,我试图弄清楚如何在运行SQL SELECT查询之前,从PHP搜索表单中的用户输入中去除特殊字符 我有一个PHP搜索表单,它将用户输入提交到selectquery>mysql 5>Linux。select查询查看一列中的相似匹配项,并将结果返回到结果页面。数据库中的列没有特殊字符-只有字母数字值 我的数据库字段值类似于33345678DEP 如果用户输入333-456*78DEP,我将如何去除特殊字符 我读过关于REGEX的文章——看起来这可能是答案,但我不知道如何实现它 执行搜索的PHP代码如下

我试图弄清楚如何在运行SQL SELECT查询之前,从PHP搜索表单中的用户输入中去除特殊字符

我有一个PHP搜索表单,它将用户输入提交到selectquery>mysql 5>Linux。select查询查看一列中的相似匹配项,并将结果返回到结果页面。数据库中的列没有特殊字符-只有字母数字值

我的数据库字段值类似于33345678DEP

如果用户输入333-456*78DEP,我将如何去除特殊字符

我读过关于REGEX的文章——看起来这可能是答案,但我不知道如何实现它

执行搜索的PHP代码如下所示:

if (isset($_GET['InventoryByVendorForm'])) {
$colname_InventoryByVendorResults = $_GET['InventoryByVendorForm'];
}
mysql_select_db($database_ic3, $ic3);
$query_InventoryByVendorResults = sprintf("SELECT icCombinedSupplier_wrk.icMaster_icmKEY, icCombinedSupplier_wrk.icsSupplierID, icCombinedSupplier_wrk.icsPartNum, icCombinedSupplier_wrk.icsQuantityOnHand, icCombinedSupplier_wrk.icsCost, icCombinedSupplier_wrk.icsCore, icCombinedSupplier_wrk.icsLastInventoryUpdate, icMaster.icmLineCode, icAttributes.`icaPartslink#` AS icaPartslink FROM icMaster INNER JOIN (icCombinedSupplier_wrk INNER JOIN icAttributes ON icCombinedSupplier_wrk.icMaster_icmKEY = icAttributes.icMaster_icmKEY) ON icMaster.icmKEY = icCombinedSupplier_wrk.icMaster_icmKEY WHERE `icCombinedSupplier_wrk`.`icMaster_icmKEY` Like %s ORDER BY icMaster_icmKEY ASC", GetSQLValueString("%" . $colname_InventoryByVendorResults . "%", "text"));
我最好的猜测是,我需要在语句周围实现REGEX[[alnum]]的使用:

$colname_InventoryByVendorResults = $_GET['InventoryByVendorForm']
如何从搜索框中的用户输入中剥离所有非字母/数字字符?

是正确的工具:

$validated = preg_replace("/[^A-Za-z0-9]/","",$colname_InventoryByVendorResults);
字母数字字符集有快捷方式,但这种方式非常直观易懂

“^”否定选择,因此任何不是字母数字的字符都将替换为空字符串

祝你今天愉快, 斯特凡