Last active
August 29, 2015 14:04
-
-
Save RyanNutt/1ff247b112a10031df69 to your computer and use it in GitHub Desktop.
One liner to get RegEx matches in PHP
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Shortcut to doing regex without needing to worry about $matches | |
* @param type $pattern | |
* @param type $search | |
* @param type $group | |
*/ | |
function preg_search($pattern, $search, $group=1) { | |
if (preg_match($pattern, $search, $matches)) { | |
if (isset($matches[$group])) { | |
return $matches[$group]; | |
} | |
return false; | |
} | |
return false; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment