rmt99e Posted July 30, 2008 Share Posted July 30, 2008 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; ?> Quote Link to comment Share on other sites More sharing options...
sasa Posted July 30, 2008 Share Posted July 30, 2008 try $pattern = '/<span id="testid">.*?<\/span>/'; Quote Link to comment Share on other sites More sharing options...
genericnumber1 Posted July 30, 2008 Share Posted July 30, 2008 try... <?php $url = "test.php"; $page = file_get_contents($url); $pattern = '%<span id="testid">(.*)</span>%'; // Changed preg_match_all($pattern, $page, $results, PREG_PATTERN_ORDER ); $conf = $results[1][0]; // Changed echo $conf; ?> Quote Link to comment Share on other sites More sharing options...
DarkWater Posted July 30, 2008 Share Posted July 30, 2008 I'd personally use sasa's regex because it made preg non-greedy with the extra ? after the quantifier. Quote Link to comment Share on other sites More sharing options...
genericnumber1 Posted July 30, 2008 Share Posted July 30, 2008 I'd personally use sasa's regex because it made preg non-greedy with the extra ? after the quantifier. Except that I don't think his works :X Quote Link to comment Share on other sites More sharing options...
rmt99e Posted July 31, 2008 Author Share Posted July 31, 2008 thanks for the advice guys! Quote Link to comment Share on other sites More sharing options...
rmt99e Posted July 31, 2008 Author Share Posted July 31, 2008 i'm still having trouble.. I tried what both of you said and still nothing is coming up. Quote Link to comment Share on other sites More sharing options...
rmt99e Posted August 1, 2008 Author Share Posted August 1, 2008 still can't get this, anyone else have input? :'( :'( Quote Link to comment Share on other sites More sharing options...
genericnumber1 Posted August 1, 2008 Share Posted August 1, 2008 What I posted works on my system, can you post the code you have here and the contents of the "test.php" file? Quote Link to comment Share on other sites More sharing options...
rmt99e Posted August 5, 2008 Author Share Posted August 5, 2008 <span id="testid"> Test Text </span> that's it! Quote Link to comment Share on other sites More sharing options...
genericnumber1 Posted August 7, 2008 Share Posted August 7, 2008 <?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 Quote Link to comment Share on other sites More sharing options...
rmt99e Posted August 7, 2008 Author Share Posted August 7, 2008 Yahtzee! Works. Thanks Bud. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.