โค้ด: เลือกทั้งหมด
function buil_sql_like($text, $limit = 3) {
global $db;
$sql_like = '';
$i = 0;
$text = str_replace(array('_', '%'), array("\_", "\%"), $text);
$text = str_replace(array(chr(0) . "\_", chr(0) . "\%"), array('_', '%'), $text);
$text = explode(' ', trim(preg_replace('`[\s]+`', ' ', $text)));
if ( !empty($text) ) {
foreach ($text as $word) {
$word = $db->sql_escape(trim($word));
$sql_like .= empty($sql_like) ? " LIKE '%$word%'" : " OR '%$word%'";
$i++;
if ($i >= $limit) {
return $sql_like;
}
}
}
return $sql_like;
}