Go Back   CodingForums.com > :: Server side development > PHP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 05-10-2012, 12:30 PM   PM User | #1
roxahh
New to the CF scene

 
Join Date: May 2012
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
roxahh is an unknown quantity at this point
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
roxahh is offline   Reply With Quote
Old 05-10-2012, 02:12 PM   PM User | #2
bjarneo
New Coder

 
Join Date: May 2012
Posts: 50
Thanks: 6
Thanked 4 Times in 4 Posts
bjarneo is an unknown quantity at this point
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.
bjarneo is offline   Reply With Quote
Old 05-18-2012, 02:12 PM   PM User | #3
roxahh
New to the CF scene

 
Join Date: May 2012
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
roxahh is an unknown quantity at this point
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
roxahh is offline   Reply With Quote
Reply

Bookmarks

Tags
code, dom, php, program, select

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 10:39 PM.


Advertisement
Log in to turn off these ads.