fork(1) download
  1. <?php
  2.  
  3. $between = array(
  4. array('hay1=', 'hay=Gold'),
  5. array('hay2=', 'hay=Silver')
  6. );
  7.  
  8. $haystack = 'Data set 1: hay2= this is a bunch of hay hay1= Gold_Needle hay=Gold
  9. Data Set 2: hay2=Silver_Needle hay=Silver';
  10.  
  11. function extract_unit($haystack, $between){
  12.  
  13. $return = array();
  14.  
  15. foreach($between as $item){
  16.  
  17. $reg = '/.*?' . $item[0] . '\s*(.*?)\s*' . $item[1] . '.*?/';
  18.  
  19. preg_match_all($reg, $haystack, $finded);
  20.  
  21. $return = array_merge($return, $finded[1]);
  22.  
  23. }
  24.  
  25. return $return;
  26.  
  27. }
  28.  
  29. print_r (extract_unit($haystack, $between));
Success #stdin #stdout 0.02s 52432KB
stdin
Standard input is empty
stdout
Array
(
    [0] => Gold_Needle
    [1] => Silver_Needle
)