 <pre><code>"select * from products where 1".cleanstring($stringval); function cleanstring($var) { $color_list = array('GOLD','RED','GREEN','WHITE'); $sql_where=''; foreach( $color_list AS $v){ if(strpos($var, $v)!==false){ $sql_where .=" AND color LIKE '%{$v}%'"; } } return $sql_where; } //select * from products where 1 OR color LIKE '%GOLD%' OR color LIKE '%RED%' </code></pre> <p>REMARK:</p> <p>input: GOLDRED ,</p> <p>match: GOLD RED,GOLD-RED,GOLD/RED..... GOLD/RED/ABC,RED_GOLDGREEN, </p> <p>may be after get all data , then make func ranking by match % ,like search engine </p>