TalkPHP
 
 
Account Login
Latest Articles
» The basic usage of PHPTAL, a XML/XHTML template library for PHP
» Vulnerable methods and the areas they are commonly trusted in.
» Simple way to protect a form from bot
» The Basics On: How Session Stealing Works
» How to keep your forms from double posting data
IRC Channel
IRC Speech Bubble Join the friendly bunch on IRC...
(#TalkPHP on Freenode)

...Also available via a web interface.

See this thread for information on the TalkPHP Free Hugs Initiative™. Subject to availability.
Associates
Associates
CSS Tutorials
Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old 02-17-2009, 12:15 AM   #1 (permalink)
The Contributor
 
Join Date: Oct 2008
Posts: 75
Thanks: 4
9three is on a distinguished road
Default Pulling values from one site as reference

Hey,

I'm trying to figure out if its possible to pull a value(s) from one site (site a) and update my site (site b) with whatever those values are?

What function is available in PHP for this, if any?
9three is offline  
Reply With Quote
Old 02-17-2009, 12:31 AM   #2 (permalink)
La Vida es Sueño
Advanced Programmer Top Contributor 
 
Wildhoney's Avatar
 
Join Date: Sep 2007
Location: Oldham
Posts: 2,280
Thanks: 90
Wildhoney is on a distinguished road
Default

How about using regular expressions? For instance, you could use this little bit of code to get the latest 5 articles from TalkPHP, as displayed on the left of the website:

php Code:
$szContent = file_get_contents('http://www.talkphp.com/forums.php');
preg_match_all('~<td class="title" valign="top">(.+?)</td>~is', $szContent, $aMatches);

foreach ($aMatches[0] as $szArticle)
{
    printf("- %s<br />\n", $szArticle);
}
__________________
The man who comes back through the Door in the Wall will never be quite the same as the man who went out.
Send a message via AIM to Wildhoney Send a message via MSN to Wildhoney Send a message via Yahoo to Wildhoney
Wildhoney is offline  
Reply With Quote
Old 02-17-2009, 05:38 AM   #3 (permalink)
The Contributor
 
Join Date: Oct 2008
Posts: 75
Thanks: 4
9three is on a distinguished road
Default

hey thanks, I'm stil learning regular expressions. Could you tell me what (.+?) does please?

Edit:

Also, I'm pulling an image from a site but it's only adding the <img src="/path/to/image.jpg"> and so the image doesn't display. I need to manually add the URL infront of it. I'm not sure how to do this within the regular expression.

Last edited by 9three : 02-17-2009 at 07:03 AM.
9three is offline  
Reply With Quote
Old 02-17-2009, 02:12 PM   #4 (permalink)
La Vida es Sueño
Advanced Programmer Top Contributor 
 
Wildhoney's Avatar
 
Join Date: Sep 2007
Location: Oldham
Posts: 2,280
Thanks: 90
Wildhoney is on a distinguished road
Default

The .+? says any character but white space, and find all those characters, but in non-greedy form, so when it finds the less than symbol "<" it will stop capturing.

For the appending of the URL to the image path, you could try something like the following:

php Code:
$aImages = array('/path/to/image.jpg', '/path/to/image.gif');
$szFunction = create_function('$s', 'return "http://www.talkphp.com" . $s;');
$aImages = array_map($szFunction, $aImages);
die(print_r($aImages, true));
__________________
The man who comes back through the Door in the Wall will never be quite the same as the man who went out.
Send a message via AIM to Wildhoney Send a message via MSN to Wildhoney Send a message via Yahoo to Wildhoney
Wildhoney is offline  
Reply With Quote
Old 02-17-2009, 02:37 PM   #5 (permalink)
Moderateur
RegEx Guru PHP Guru Top Contributor Advanced Programmer 
 
Salathe's Avatar
 
Join Date: Apr 2007
Posts: 1,393
Thanks: 5
Salathe is on a distinguished road
Default

Quote:
Originally Posted by Wildhoney View Post
The .+? says any character but white space
Not strictly true. By default, . will match any character which isn't the newline character (so the same as [^\n]): any other whitespace character (like space, tab, carriage return) will be matched. With the s (PCRE_DOTALL) modifier, the dot will match any character (including the newline).
Salathe is offline  
Reply With Quote
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
The most inventive way to switch 2 values Wildhoney Tips & Tricks 32 08-10-2010 05:10 AM
How to make an RSS aggregator site ? vuthcam Advanced PHP Programming 1 02-03-2009 10:12 PM
Gaming Site Redux obolus Show Off 3 02-25-2008 09:52 PM
Recently rebuilt site obolus Show Off 6 10-30-2007 02:24 AM
Lowdown on Passing Things as Reference Wildhoney General 0 09-28-2007 10:57 AM


All times are GMT. The time now is 12:17 PM.

 
     

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0
Inactive Reminders By Icora Web Design