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 3 of 3
  1. #1
    New to the CF scene
    Join Date
    May 2012
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question PHP Dom - Program to select, and code?

    Hello

    I'm not the best at php, but i want to use php dom to grab some content from a site and paste it on mine (with an interval in hours). but i have searched for some days now.. and found out that it's complicated to use. anyway the question is, do anyone know if there's a program where i can select the code i want to grab and then the program do the rest?

    Thanks in advance

  • #2
    New Coder
    Join Date
    May 2012
    Posts
    50
    Thanks
    6
    Thanked 4 Times in 4 Posts
    I don't know any program. But maybe you can tweak this regex / code to fetch whatever you want from the site DOM.

    This code fetch all links from codingforums.com php thread.
    file_get_contents() php.net: http://no.php.net/manual/en/function...t-contents.php

    PHP Code:
    <?php

    $html 
    file_get_contents('http://www.codingforums.com/forumdisplay.php?f=6');
    $links pc_link_extractor($html);
    foreach(
    $links as $link)
    {
        print 
    $link[0] . "<br />\r\n";
    }

    function 
    pc_link_extractor($html)
    {
        
    $links = array();
        
    preg_match_all('/<a\s+.*?href=[\"\']?([^\"\' >]*)[\"\']?[^>]*>(.*?)<\/a>/i'$html$matchesPREG_SET_ORDER);
        foreach(
    $matches as $match)
        {
            
    $links[] = array($match[1], $match[2]);
        }
        return 
    $links;
    }


    ?>
    If you want to grab the content with an interval in hours, use cronjobs. (If this is available).


    Edit: cURL is also an option.

    Last edit: http://php.net/manual/en/book.dom.php and http://www.php.net/manual/en/domdocu...lementbyid.php
    Last edited by bjarneo; 05-10-2012 at 02:30 PM. Reason: dom document.

  • #3
    New to the CF scene
    Join Date
    May 2012
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Thanks for the response I'll look at it and try to get it to work and let u know if i get a problem :P


  •  

    Tags for this Thread

    Posting Permissions

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