Hi, I'm trying to find the Link Title within the following: <li class="cuisine"> Cuisine <a title="New Zealand food" href="/search.php?"> New Zealand </a> Code (markup): I'm using the following php: preg_match_all('~<li class="cuisine"> Cuisine <a title="(.*?)"~s', $html, $cuisineMatches); foreach ($cuisineMatches[1] AS $cuisineMatch) { //echo "Cuisine: ".str_replace(" recipes", "", $cuisineMatch)."<br />"; } PHP: But in some instances the white space changes so it can't find the match, what can I do about this? Thanks
use this instead: preg_match_all('~<li class="cuisine">(\s*?)Cuisine(\s*?)<a title="(.*?)"~is', $html, $cuisineMatches); foreach ($cuisineMatches[1] AS $cuisineMatch) { //echo "Cuisine: ".str_replace(" recipes", "", $cuisineMatch)."<br />"; } PHP: