这是我试图让搜索引擎获取输入为 Doe J 而不是 Doe, J 的名称。
这是我的代码:
$sql_where = array();
if (isset($_GET['name'])) {
echo "Searched: {$_GET['name']}<br>";
$names = explode(' ', trim(preg_replace('/ +/', ' ', $_GET['name'])));
$names_cnt = count($names);
if (2 == $names_cnt) {
foreach ($names as $name_idx => $name) {
if (($name_idx+1) == $names_cnt) {
// last one
$sql_where[] = "
(full_name like '% {$name}%')
";
} else {
// first one
$sql_where[] = "
(full_name like '{$name}%')
";
}
}
} else {
$sql_where[] = "
(full_name like '" . $DB->cleanString($_GET['name']) . "%')
";
我已经尝试过/[^a-zA-Z0-9 ]/
以及其他一些不成功的变体。