code_junkie

RegEx() — how to parse zip codes out of text

Nov 13th, 2011
177
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.37 KB | None | 0 0
  1. <?php
  2. $str = 'Munson 11010 Shelter Island Heights. . . .. 11965 Brentwood 11717 Halesite 11743 ';
  3.  
  4. preg_match_all("/d{5}/", $str, $matches);
  5.  
  6. print_r($matches);
  7. ?>
  8.  
  9. preg_match_all('[^0-9]([0-9]{5})[^0-9]', $input, $out);
  10. foreach($out as $val)
  11. echo $val[1] . "n";
  12.  
  13. preg_match_all("/d{5}/", $input, $matches);
  14.  
  15. foreach($matches[0] as $zip){
  16. echo $zip.'<br/>';
  17. };
Add Comment
Please, Sign In to add comment