can't get strstr to work
Posted: Mon Feb 14, 2005 9:50 pm
I can't understand why I can't find needle in haystack... I am using file_get_contents to get a page of search engine results. Then I search the page to find any anchor tags and put them into the $links array. I am trying to loop through the array and find all of the links that start with "http://" and add them to another array. If it doesn't start with http:// then it's one of the engine's local links.
I'm trying to get it to remove any anchor tag that is a local link but it's not working. Here's the code.
I've tried using, after the strstr() line (if(...) continue;) also and it didn't work either. Does anyone see what I have wrong?
...and sorry about the half post. I was trying to make my code more legible by taking out the comments and erased the problem bit.
Thanks
I'm trying to get it to remove any anchor tag that is a local link but it's not working. Here's the code.
Code: Select all
<form method="get" action="pod_search3.php" name="pod_search">
<input type="text" name="terms" id="terms" />
<input type="hidden" name="target" id="target" value="http://www.google.com/search" />
<input type="submit" value="find mph-cast" />
</form>
Thanks,
<?php
$search_terms = $_GETї'terms'];
$target_engine = $_GETї'target'];
$search_terms = str_replace(" ", "+", $search_terms);
$guy = web_search($search_terms, $target_engine);
function web_search($terms, $target)
{
if($terms)
{
$query = array();
$query = "$target?hl=en&num=100&li=&q=$terms";
print($query . "<br>");
$result = file_get_contents($query);
// gets all anchor tags on page
$pattern = '/(<a .*<\/a>)/i';
preg_match_all($pattern, $result, $links);
$pagelinks = array();
$num = 0;
// here is the part that's not working
for($i=0;$i<count($linksї0]);$i++)
{
// what I am trying to say in the next line is, "if http:// is not in the
// next element, do nothing. otherwise add it to a new array.
if(!strstr("http://", $linksї0]ї$i])) ;
else {
$pagelinksї$num] = $linksї0]ї$i];
print($pagelinksї0]); //($pagelinksї$num] . "<br />");
$num++;
}
}
/*foreach($linksї0] as $link)
{
//works
print("$num - " . $link . "<br />");
++$num;
}*/
}
else print("enter search term");
}
?>Code: Select all
continue...and sorry about the half post. I was trying to make my code more legible by taking out the comments and erased the problem bit.
Thanks