Code:
$Target = "phrase 2"
$textarea_array=array("phrase 1","phrase 2");
foreach ($textarea_array as $XQuery) {
$html = "http://www.mysite.co.uk/search?api=" .$XQuery;
$dom = new DOMDocument;
@$dom->loadHTMLFile($html);
$xpath = new DOMXPath($dom);
$aTag = $xpath->query('//h3[@class="r"]/a');
foreach ($aTag as $val) {
$arr[] = $val->getAttribute('href');
}
foreach($arr as $key => $value)
{
if(stristr($value, $Target))
{
$Position = $key;
break;
}
else {
$Position = "Not Found";
}
}
echo $XQuery;
echo "-";
echo $Position;
echo "<br><br>";
}
What
should be being output is
phrase 1 - position of phrase 1
phrase 2 - position of phrase 2
What is
actually being output is
phrase 1 - position of phrase 1
phrase 2 - position of phrase
1
And I just can see why!?