CodingForums.com

CodingForums.com (http://www.codingforums.com/index.php)
-   PHP (http://www.codingforums.com/forumdisplay.php?f=6)
-   -   PHP Dom - Program to select, and code? (http://www.codingforums.com/showthread.php?t=260818)

roxahh 05-10-2012 12:30 PM

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

bjarneo 05-10-2012 02:12 PM

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

roxahh 05-18-2012 02:12 PM

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


All times are GMT +1. The time now is 07:14 PM.

Powered by vBulletin®
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.