I have never really used regular expressions all that much and as such i have a few questions.
Basically i have built a simple class that returns text inbetween user specified tags.
function getData($tagname){
$this->tagname = $tagname;
$string = $this->dump;
$pattern = "/<$tagname>(.*?)<\/$tagname>/s";
preg_match($pattern,$string,$matches,PREG_OFFSET_CAPTURE);
print_r($matches);
}
This is giving me the info required but its returning multiple copies in the array, im just wondering what the reason behind this is?
For example
$depData->getData('departureTime');
Returns
Array ( [0] => Array ( [0] => 2012/03/07 12:45:13 [1] => 41 ) [1] => Array ( [0] => 2012/03/07 12:45:13 [1] => 56 ) )
Im thinking that its something to do with my regex being to vague?
It’s giving giving you 2 results first is for the whole expresion
<tag>(.*?)</tag>and the second result is for the result in the parentheses(.*?)Also I created an example for you to see the difference between the first capture (whole expression) and the parentheses capture (your serach).
http://xrg.es/#1ompqhf
Note: I replaced
<and>with"for you to see more clearly what’s different.