Jump to content

Retrieving Content with file_get_contents()


rmt99e

Recommended Posts

Hey, I'm trying to make a spider to get all the content within a <span> tag on another page. This is the first time i've done something like this. I was able to make it work by just searching for a number, but not searching for a table or anything else. Thanks for the help.

 

 

 

<?php
$url = "test.php"; // URL

$page = file_get_contents($url);

//$pattern = '/ \d\-\d+ /';
$pattern = '/ <span id="testid"><\/span> /';

preg_match_all($pattern, $page, $results, PREG_PATTERN_ORDER );

$conf = $results[0][1]; 

echo $conf;

?>

<?php

$url = "test.txt";

 

$page = file_get_contents($url);

 

$pattern = '%<span id="testid">(.*)</span>%s';

 

preg_match_all($pattern, $page, $results, PREG_PATTERN_ORDER );

 

$conf = $results[1][0];

 

echo $conf;

?>

 

Give that a try

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.