Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 12 of 12
  1. #1
    Regular Coder sonny's Avatar
    Join Date
    Apr 2008
    Location
    United States
    Posts
    567
    Thanks
    88
    Thanked 0 Times in 0 Posts

    Check for text on a page true or false

    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?

    PHP Code:
    function url_exists$strURL NULL )
    {
        if ( !
    preg_match'/^http(s?):\/\//i'$strURL$m ) )
            return 
    NULL;
        @
    $ch curl_init();
        
    curl_setopt$chCURLOPT_URL$strURL );
        
    curl_setopt$chCURLOPT_BINARYTRANSFER);
        
    curl_setopt$chCURLOPT_HEADERFUNCTION'curlHeaderCallback' );
        
    curl_setopt$chCURLOPT_FAILONERROR);
        
    curl_setopt$chCURLOPT_TIMEOUT);
        
    // https?
        
    if ( $m[1] == 's' )
            
    curl_setopt$chCURLOPT_SSL_VERIFYPEER);
        @
    curl_exec$ch );
        
    $intReturnCode curl_getinfo$chCURLINFO_HTTP_CODE );
        
    curl_close$ch );
        return ( 
    $intReturnCode == 200 OR $intReturnCode == 302 OR $intReturnCode == 304 ) ? TRUE FALSE;


    Thanks
    Sonny

  • #2
    Supreme Master coder! _Aerospace_Eng_'s Avatar
    Join Date
    Dec 2004
    Location
    In a place far, far away...
    Posts
    19,291
    Thanks
    2
    Thanked 1,043 Times in 1,019 Posts
    I think another function may be better but you could incorporate it into what you have. You can do this
    PHP Code:
    function checkword($url,$str)
    {
        
    $newcontents '';
        if(
    url_exists($url))
        {
            
    $ch curl_init();
            
    curl_setopt ($chCURLOPT_URL$url);
            
    curl_setopt ($chCURLOPT_HEADER0);
            
    ob_start();
            
    curl_exec ($ch);
            
    curl_close ($ch);
            
    $contents ob_get_clean();
            
    $newcontents preg_replace('!\s+!smi'," "$contents );
        }
        if(
    strpos($newcontent,$str) !== -|| 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.
    ||||If you are getting paid to do a job, don't ask for help on it!||||

  • #3
    Regular Coder sonny's Avatar
    Join Date
    Apr 2008
    Location
    United States
    Posts
    567
    Thanks
    88
    Thanked 0 Times in 0 Posts
    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

  • #4
    Senior Coder
    Join Date
    Jul 2009
    Location
    South Yorkshire, England
    Posts
    2,318
    Thanks
    6
    Thanked 304 Times in 303 Posts
    Quote Originally Posted by sonny View Post
    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.

  • #5
    Regular Coder sonny's Avatar
    Join Date
    Apr 2008
    Location
    United States
    Posts
    567
    Thanks
    88
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by MattF View Post
    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

  • #6
    Senior Coder
    Join Date
    Jul 2009
    Location
    South Yorkshire, England
    Posts
    2,318
    Thanks
    6
    Thanked 304 Times in 303 Posts
    Quote Originally Posted by sonny View Post
    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.

  • #7
    Regular Coder sonny's Avatar
    Join Date
    Apr 2008
    Location
    United States
    Posts
    567
    Thanks
    88
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by MattF View Post
    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
    Last edited by sonny; 02-14-2010 at 09:16 PM. Reason: spelling error

  • #8
    Senior Coder
    Join Date
    Jul 2009
    Location
    South Yorkshire, England
    Posts
    2,318
    Thanks
    6
    Thanked 304 Times in 303 Posts
    Quote Originally Posted by sonny View Post
    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. I'm supposedly the one with an attitude, btw?

  • #9
    Regular Coder sonny's Avatar
    Join Date
    Apr 2008
    Location
    United States
    Posts
    567
    Thanks
    88
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by MattF View Post
    That is, respectively, forefathers, country and sum. I'm supposedly the one with an attitude, btw?
    Ok, I see I am dealing with an English major my bad , and now
    I guess that renders everything I said in my post mute
    oh dear better use spell check next time

  • #10
    Supreme Master coder! _Aerospace_Eng_'s Avatar
    Join Date
    Dec 2004
    Location
    In a place far, far away...
    Posts
    19,291
    Thanks
    2
    Thanked 1,043 Times in 1,019 Posts
    Quote Originally Posted by sonny View Post
    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.
    Last edited by _Aerospace_Eng_; 02-15-2010 at 01:53 AM.
    ||||If you are getting paid to do a job, don't ask for help on it!||||

  • #11
    Regular Coder sonny's Avatar
    Join Date
    Apr 2008
    Location
    United States
    Posts
    567
    Thanks
    88
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by _Aerospace_Eng_ View Post
    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

  • #12
    Regular Coder
    Join Date
    Jan 2010
    Posts
    101
    Thanks
    17
    Thanked 5 Times in 5 Posts
    I'm not to familiar with cURL, but you could use file_get_contents to get the contents of the website, and use some sort of string search to search the contents of the site.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •