thevoipman
thevoipman

Reputation: 1833

curl for a particular row/phrase

I'm trying to curl searchbug.com to see if it returns the phrase: "VoIP (Voice over IP, Internet Phone)" If it returns that then make $voip==TRUE;

Here's what I have and am sure i'm missing something here. Any kind of help I can get is greatly appreciated!

$url = 'http://www.searchbug.com/tools/landline-or-cellphone.aspx?&FULLPHONE=2093201364';
$useragent = 'Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US) AppleWebKit/533.2 (KHTML, like Gecko) Chrome/5.0.342.3 Safari/533.2';
$ch = curl_init($link);

curl_setopt($ch, CURLOPT_USERAGENT, $useragent);
curl_setopt($ch, CURLOPT_HEADER, true);
curl_setopt($ch, CURLOPT_NOBODY, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

$response = curl_exec($ch);
curl_close($ch);

if ($response="VoIP (Voice over IP, Internet Phone)") { $voip==True; }

Upvotes: 0

Views: 81

Answers (1)

Andrey Volk
Andrey Volk

Reputation: 3549

First point. Do not exclude the body from the output.

You use:

curl_setopt($ch, CURLOPT_NOBODY, true);

PHP documentation says:

CURLOPT_NOBODY - TRUE to exclude the body from the output.

Second point. Check better the response

What you do. You assign "VoIP (Voice over IP, Internet Phone)" string value to the $response and then check it for not null. Yes, it is not null.

if ($response="VoIP (Voice over IP, Internet Phone)") { $voip==True; }

So then php executes
Third wrong point:

$voip==True;  // Wrong! It is a conditional expression
$voip = true; // Ok;

Drop curl_setopt($ch, CURLOPT_NOBODY, true); and try this instead:

if ( strpos($response, "VoIP (Voice over IP, Internet Phone)") !== false )
{
    $voip = true;
}

$response may contain a lot of data. So strpos might be helpful.

Upvotes: 1

Related Questions