Return to Snippet

Revision: 68765
at February 21, 2015 11:34 by jatubio


Initial Code
function preg_match_first($pattern,$string,$result_number=null)
{
	if(is_null($result_number)) $result_number=0;
	preg_match($pattern,$string,$matches);
	return !empty($matches)?$matches[$result_number]:"";
}

Initial URL


Initial Description
Search and returns the first results on a regex search
If we use parenthesized or subpattern, can return with $result_number

Initial Title
Search and returns the first results on a regex search

Initial Tags
regex

Initial Language
PHP