Posted By

jatubio on 02/21/15


Tagged

regex pregmatch


Versions (?)

Search and returns the first results on a regex search


 / Published in: PHP
 

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

  1. function preg_match_first($pattern,$string,$result_number=null)
  2. {
  3. if(is_null($result_number)) $result_number=0;
  4. preg_match($pattern,$string,$matches);
  5. return !empty($matches)?$matches[$result_number]:"";
  6. }

Report this snippet  

You need to login to post a comment.