...

View Full Version : Check for text on a page true or false



sonny
02-14-2010, 02:06 AM
below is a function to check if a url exist, I would like to also check for
text on the page as well, does anybody know how I can incorporate
that into this code, or should it be another function?



function url_exists( $strURL = NULL )
{
if ( !preg_match( '/^http(s?):\/\//i', $strURL, $m ) )
return NULL;
@$ch = curl_init();
curl_setopt( $ch, CURLOPT_URL, $strURL );
curl_setopt( $ch, CURLOPT_BINARYTRANSFER, 1 );
curl_setopt( $ch, CURLOPT_HEADERFUNCTION, 'curlHeaderCallback' );
curl_setopt( $ch, CURLOPT_FAILONERROR, 1 );
curl_setopt( $ch, CURLOPT_TIMEOUT, 5 );
// https?
if ( $m[1] == 's' )
curl_setopt( $ch, CURLOPT_SSL_VERIFYPEER, 0 );
@curl_exec( $ch );
$intReturnCode = curl_getinfo( $ch, CURLINFO_HTTP_CODE );
curl_close( $ch );
return ( $intReturnCode == 200 OR $intReturnCode == 302 OR $intReturnCode == 304 ) ? TRUE : FALSE;

}


Thanks
Sonny

_Aerospace_Eng_
02-14-2010, 02:59 AM
I think another function may be better but you could incorporate it into what you have. You can do this

function checkword($url,$str)
{
$newcontents = '';
if(url_exists($url))
{
$ch = curl_init();
curl_setopt ($ch, CURLOPT_URL, $url);
curl_setopt ($ch, CURLOPT_HEADER, 0);
ob_start();
curl_exec ($ch);
curl_close ($ch);
$contents = ob_get_clean();
$newcontents = preg_replace('!\s+!smi'," ", $contents );
}
if(strpos($newcontent,$str) !== -1 || strpos($newcontent,$str) !== false)
return true;
else return false;
}
echo checkword('http://www.google.com','privacy');
A function should do one thing only and be good at what it does. With the above I'm sure you can see how you may be able to do it. I couldn't test it but it should work.

sonny
02-14-2010, 04:16 AM
Thanks I cant get that to work with my other code,

I am trying to see if my page is available online if not I send a email I have
that part working ok that function I posted works if there is no site using this
$url "mydomain.com";

what I am trying to add is to check the url page for some text as well I
specify in lets say $lookfor "test"; // in this case the text would be test of
course

if there is no test my email code will then email test not right please
investigate etc

I just need to implement that into my function above that is the only thing
holding me up

if you can show me exactly what the finished function above should look like
that would be super

Thanks
Sonny

MattF
02-14-2010, 11:37 AM
if you can show me exactly what the finished function above should look like that would be super

It would be even better if you attempted finishing the function yourself, first. Helping and doing the coding for you are two different things. I'm sure there are some who may post a complete version of what you want, but that's not really the point of this forum, is it.

sonny
02-14-2010, 04:03 PM
It would be even better if you attempted finishing the function yourself, first. Helping and doing the coding for you are two different things. I'm sure there are some who may post a complete version of what you want, but that's not really the point of this forum, is it.

whats with the attitude? I have been a member here for a long time, go post you nasty 2 cent comments some where else!

For you information I did, try for weeks and then for hours last night that's why I posted on the forum

Sonny

MattF
02-14-2010, 06:52 PM
whats with the attitude? I have been a member here for a long time, go post you nasty 2 cent comments some where else.

How I just love Prima Donna's, (and by God, there's no shortage of them). That wasn't even slightly tactless, in my book. You'd have known if I was saying it nastily.

sonny
02-14-2010, 07:19 PM
How I just love Prima Donna's, (and by God, there's no shortage of them). That wasn't even slightly tactless, in my book. You'd have known if I was saying it nastily.

Boy, do you got that backwards, Your just a wise guy anybody reading your
post can see you are being condescending. Sorry but I do not use
a degree meter, and your php skill an't all that to boot. by posting a reply like
you did, you all but killed any chance of help I might have gotten, you knew
what you where doing and for no reason at all.

If there was any doubt about why my forefathers booted you guys out of the
Country, you just about some it up.

Sonny

MattF
02-14-2010, 08:03 PM
If there was any doubt about why my for fathers booted you guys out of the Country, you just about some it up.

That is, respectively, forefathers, country and sum. :rolleyes: I'm supposedly the one with an attitude, btw?

sonny
02-14-2010, 08:29 PM
That is, respectively, forefathers, country and sum. :rolleyes: I'm supposedly the one with an attitude, btw?

Ok, I see I am dealing with an English major my bad :o, and now
I guess that renders everything I said in my post mute :rolleyes:
oh dear better use spell check next time :thumbsup:

_Aerospace_Eng_
02-15-2010, 12:50 AM
whats with the attitude? I have been a member here for a long time, go post you nasty 2 cent comments some where else!

For you information I did, try for weeks and then for hours last night that's why I posted on the forum

Sonny

And I've been here longer. Did you even try what I gave you? If you really did try then show us what you tried. We are here to help you. We are not here to just give you code. Its your job to try things on your own. Good luck.

sonny
02-15-2010, 05:42 AM
And I've been here longer. Did you even try what I gave you? If you really did try then show us what you tried. We are here to help you. We are not here to just give you code. Its your job to try things on your own. Good luck.

What is this a tag team match now, ganging up with your sole mate bloody
MattF?

You guys are mate worthy funky smelling rates, bet you didn't know it? but
My FireFox browser has the sense around plug in, I can smell the both of you
"unfortunately" as if I was standing right next to you, and its making me
throw up profusely,

For your sakes, I hope your offspring fare better in the brains/oder dept.
nothing like coming out of MattF's womb a card short of a deck, because
your screwed as it is to start with.

please for proper spelling and punctuation have your pretty boy AKA- red
coat MattF do his proofing routine. its the only code that seems to work
right between the both of you.

JMO
Sonny

iLochie
02-15-2010, 08:50 AM
I'm not to familiar with cURL, but you could use file_get_contents (http://php.net/file_get_contents) to get the contents of the website, and use some sort of string search to search the contents of the site.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum