I know, this question isn't actual but I've solved similar problem :)
My solution:
/** * SQL Like operator in PHP. * Returns TRUE if match else FALSE. * @param string $pattern * @param string $subject * @return bool */ function like_match($pattern, $subject) { $pattern = str_replace('%', '.*', preg_quote($pattern, '/')); return (bool) preg_match("/^{$pattern}$/i", $subject); } Examples:
like_match('%uc%','Lucy'); //TRUE like_match('%cy', 'Lucy'); //TRUE like_match('lu%', 'Lucy'); //TRUE like_match('%lu', 'Lucy'); //FALSE like_match('cy%', 'Lucy'); //FALSE