Hi,
my problem is in regular expression. I need to catch from html code hyperlink tag's href atribute content if this hyperlink contains search condition.
here is snippet:
$a = "nail"; //search ctriteria between <a></a>
$s =<<<EOF
<a class="level2" onmouseout="this.style.background = '';" onmouseover="this.style.background ='#2c7cf4';" href="index.php?item&module=1&category=11" style=""> kaut kas cits </a>
<img> </img>
<br>
<a class="level2" onmouseout="this.style.background = '';" onmouseover="this.style.background ='#2c7cf4';" href="index.php?item&module=1&category=13" style=""> nails </a>
<a class="level2" onmouseout="this.style.background = '';" onmouseover="this.style.background ='#2c7cf4';" href="index.php?item&module=1&category=15" style=""> kaut kas cits2 </a>
EOF;
//this is how far i figured it out
$regexp = "#<a\s[^>]*href=\"([^\"]*)\"[^>]*>(.*{$a}+.*)</a>#siU";
/* rule explanation
# - store pattern
\s - whitespace char
. - any char (exclude newline)
* - 0 or more
? - match minimal string combo
s - (PCRE_DOTALL) modifier
i - match UPPER or lower case letters
^ - not
U - (PCRE_UNGREEDY) modif.
*/
//finding all hyperlinks
preg_match_all($regexp, $s, $matches);
// result must be 'index.php?item&module=1&category=13'
var_dump($matches);
it would be nice if you help me out with this regexp. Thanks!