Forum Moderators: coopster

Message Too Old, No Replies

site checker not comfirming all present URLs

         

sukebe

7:22 am on Jun 10, 2010 (gmt 0)

10+ Year Member



I have this function that gets fed a url and a couple of search terms that are known to be in the url. Unfortunately, not all urls pass, even though they exist.
this url does not get confirmed:
<snip>
--------
whereas, this one does:
<snip>

both contain the word 'tie'.

what could be missing? I tried dropping the case of the site, but that didn't help.

-------------------------------
function urlExists($url=NULL, $findme, $findme2)
{
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_TIMEOUT, 1600);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 1600);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$data = strtolower(curl_exec($ch));
$httpcode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);

$pos = strpos($data, $findme);
$pos2 = strpos($data, $findme2);
if ($pos == true) {
print("<span style='color:#00FF00'>".$url."</span><BR>");
return true;
}
elseif ($pos2 == true) {
print("<span style='color:#00FFf0'>".$url."</span><BR>");
return true;
}
}

[edited by: dreamcatcher at 7:28 am (utc) on Jun 10, 2010]
[edit reason] No urls please. See TOS. [/edit]

sukebe

6:13 pm on Jun 10, 2010 (gmt 0)

10+ Year Member



oops, I guess I can't give sample urls.

dreamcatcher

8:24 am on Jun 11, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Sory, sukebe. This is our policy here. If you want to try using url examples that don`t directly link to live sites thats fine. If you use example.com thats acceptable.

If you want to try adding a little more info, maybe someone can help.

dc

coopster

12:17 pm on Jun 11, 2010 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



Unfortunately, not all urls pass, even though they exist.


That may be your issue. Check the status of the http code and/or the data returned ... are you certain your connection is successful AND returning the data?

brotherhood of LAN

12:25 pm on Jun 11, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



re: strpos, from the manual

[php.net...]
Warning

This function may return Boolean FALSE, but may also return a non-Boolean value which evaluates to FALSE, such as 0 or "". Please read the section on Booleans for more information. Use the === operator for testing the return value of this function.


It may return false if you're matched text is at the start of the string, i.e. position 0.

sukebe

5:37 pm on Jun 11, 2010 (gmt 0)

10+ Year Member



thanks guys, I had the script print out the page before, but that got clogged up pretty quick with alot of URLs. I'm not sure how else I could test if its being read or not. in the case of strpos, the beginning of the str is going to be standard html openings. Still, I'll see about using something else.

Thanks

TheMadScientist

6:00 pm on Jun 12, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



You don't need to use anything different than strpos(), just make sure you're checking correctly.

if ($pos !== false)

== results in 'false' for position 0, which is the first position in the string, but === only results in 'false' for false (no match in the string).