Jump to content

Curl to check for certain text on a webpage


doa24uk

Recommended Posts

Hi guys,

 

I'm wondering if someone could advise or point me in the direction of a good tutorial for the following.

 

Let's say I have two pages. A & B

 

Page A contains a link to Page B

 

I want to check for certain text contained on Page B (it will always be in the same place.

 

So, if Page B says

 

<div id=mydiv>Positive Negative</div>

 

Then I can code something in php (this bit I can do) to update Page A with the text

 

Unfortunately, Page B Result was NEGATIVE

 

Otherwise it will post something on Page A saying

 

Great, Page B Result was POSITIVE

 

 

---

 

Thanks in advance!

Regex is your best option, although I'm not the best at regex so I'd probably do something like:

$file = file_get_contents("a.php");
$split = explode('<div id=mydiv>Positive Negative</div>',$file);
if (count($split) > 1)
{
//div was found
}
else
{
//div was not found
}

Admittedly, this is not the best way to do it, but it will work.

Regex is your best option, although I'm not the best at regex so I'd probably do something like:

$file = file_get_contents("a.php");
$split = explode('<div id=mydiv>Positive Negative</div>',$file);
if (count($split) > 1)
{
//div was found
}
else
{
//div was not found
}

Admittedly, this is not the best way to do it, but it will work.

 

Sorry, I should have mentioned that a.php in your example & Page B will be an offsite page therefore this won't work :(

im pretty sure it will still work as he said if i remember right you can get file contents from their page

 

$file = file_get_contents("http://google.com");
$split = explode('<div id=mydiv>Positive Negative</div>',$file);
if (count($split) > 1)
{
//div was found
}
else
{
//div was not found
}

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.