Skip to main content
This change follows @John Reid comment.
Source Link

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 

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 

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 
Source Link

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