
Untitled
By: a guest on
Jul 24th, 2012 | syntax:
None | size: 0.95 KB | hits: 8 | expires: Never
Non alphanumeric characters replaced with a single space
$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']) . "%')
";
echo preg_replace( "`[^a-zA-Z0-9]+`", " ", $string);
//replaces all non alpha numeric characters as " "
//(and will not have duplicate spaces)