Jump to content

[SOLVED] preg_match_all Question


JSHINER

Recommended Posts

<?php
for ($n = 0; $n < 1000; $n = $n + 50)
{
   
$seed = "http://www.site.com/page=$n";
$data = file_get_contents($seed);

if (preg_match_all("/\http:[^\"\s']+/", $data, $links)) 

{

@header("Content-type: text/plain");

     for ($i=0;$i<count($links[0]);$i++) 
     {
        // echo $links[0][$i]. "\n";
          
       	echo substr($links[0][$i], 7, 100). "\n";

     }
}
}
?>

 

The above goes from page to page getting info. Works great.

 

However I need it to now dig deeper. I need it to take a preg_match_all for lets say example the text in a link that is name=TEXT&other=stuff - then go to a next page which has an address of http://www.site.com/page=TEXT (basically just insert "TEXT" and then gather info on all of those pages (TEXT1, TEXT 2, etc) - and display ALL results from those sub pages.

 

I hope this makes sense. :)

Link to comment
Share on other sites

Let's say I start at /page_a.html and on that page there are links: link.php?id=202 .... link.php?id=494 etc

 

And those all link to the same pages just different ID's

 

So my next step would be to gather info on all of the sub pages on that page so it would then go to link.php?id=$found

 

Does that make sense?

Link to comment
Share on other sites

Let's say I start at /page_a.html and on that page there are links: link.php?id=202 .... link.php?id=494 etc

 

And those all link to the same pages just different ID's

 

So my next step would be to gather info on all of the sub pages on that page so it would then go to link.php?id=$found

 

Does that make sense?

 

I think that's what I said. In this case you need to loop through your preg_match_all results and run a new expression against the results.

Link to comment
Share on other sites

I tried with this:

 

<?php
$seed = "http://www.site.com/sub/index.htm";
$data = file_get_contents($seed);
if (preg_match_all("/http:\/\/www.site.com\/sub\/[^\"\s']+/", $data, $links)) 
{
     for ($i=0;$i<count($links[0]);$i++) 
     {
	$data_b = file_get_contents($links[0][$i]);

if (preg_match_all("/\http:[^\"\s']+/", $data_b, $links_b)) 
{

header("Content-type: text/plain");

     for ($i_b=0;$i_b<count($links_b[0]);$i_b++) 
     
     {
     
     echo $links_b[0][$i_b]. "\n";
     }
}
}
}
?>

 

But this does not work. Does anyone see the problem?

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.