Jump to content

[SOLVED] reading partial code from external site


daveh33

Recommended Posts

Hi,

 

I am trying to write a script for my website to get an article from an external website. The external website has the article in a set of tags <roottag> & </roottag>

 

The code I am using is

$page = file_get_contents($url);
preg_match_all("/<roottag>.+<\/roottag>/", $page, $matches);
print_r($matches);

 

when this code runs the below is output: -

 

Array ( [0] => Array ( ) )

 

I've not used this function in php and am a bit stuck! so any help is really appreciated

Link to comment
Share on other sites

try:

 

<?php
$url = "http://www.thesun.co.uk/sol/homepage/sport/other_sports/racing/1142207/Templegates-racing-tips.html";
$page = file_get_contents($url);
preg_match_all("~\<roottag\>(.+?)\<\/roottag\>~s", $page, $matches);
print_r($matches);
?>

 

edit: Late

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.