Skip to content

Instantly share code, notes, and snippets.

@Loupax
Last active October 6, 2015 14:27
Show Gist options
  • Select an option

  • Save Loupax/a39e356f68da7b96f8ef to your computer and use it in GitHub Desktop.

Select an option

Save Loupax/a39e356f68da7b96f8ef to your computer and use it in GitHub Desktop.
<?php
/**
* 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);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment