Im trying to understand how the preg_match function in PHP works, but I just can't get the result I want.
Basically I have a string "html", which contains HTML code and I need to extract part of it, so the string looks like this:
... <div class="countrys CZ level1" id="CZ" alt="Česká republika" ><span class="warn awt l3 t2"></span><div class="tendenz awt nt l3"></div></div></a></td><td class
...
In this string I want to extract everything contained in the div with id="CZ", not including what then continues in div class="tendenz....
So far I tried this:
preg_match("/alt=\"Česká republika\" >(.*)/", $html, $results);
echo $results[1];
This way I got the beginning right, so everything from the start, but until the end of string, not only until the start of the next div.So then I tried:
preg_match("/alt=\"Česká republika\" >(.*)<div/", $html, $results);
echo $results[1];
But for some reason I am still getting the beginning correctly, but then it goes on until the end of the string, not finishing with the next "div".
Any ideas what is wrong with my code? I really appreciate your help.