Grab a useful link in a page, crawl the link on the page, use a For loop, but loop to the second time to make a mistake,
Think for a while, do not know the problem where, please the great God to help you look.
$url = ' Http://www.meishij.net/chufang/diy/?page=1#listnav '; $opts = Array (' http ' =>array (' user_agent ' = = "Moz illa/4.0 (compatible; MSIE 5.01; Windows NT 5.0) ",)); $context = Stream_context_create ($opts); $con = file_get_contents ("$url", false, $context);//Entry $preg = ' #(.*)#'; Preg_match_all ($preg, $con, $arr); The search content is assigned to the array for ($i =0; $i <20; $i + +)//single-page intercept {//print_r ($arr [0][$i]); $SS = $arr [2][$i]; Echo $ss; echo "
"; $opts = Array (' http ' =>array (' user_agent ' = = "mozilla/4.0 (compatible; MSIE 5.01; Windows NT 5.0) ",)); $context = Stream_context_create ($opts); $cons = file_get_contents ("$ss", false, $context);//Title $preg = ' #(.*)
#'; Preg_match_all ($preg, $cons, $arr); The search content is assigned to the array print_r ($arr [0][0]);//Content $preg = ' #(.*) (.*)
#'; Preg_match_all ($preg, $cons, $arr); The search content is assigned to the array print_r ($arr [0][0]); echo "
";p Rint_r ($arr [0][1]); echo"
";p Rint_r ($arr [0][2]); echo"
";//Picture $preg = ' ##'; Preg_match_all ($preg, $cons, $arr); The search content is assigned to the array print_r ($arr [0][0]); echo "
";p Rint_r ($arr [0][1]); echo"
";p Rint_r ($arr [0][2]); echo"
";p Rint_r ($arr [0][3]); echo"
";p Rint_r ($arr [0][4]); echo"
";p Rint_r ($arr [0][5]); echo"
";p Rint_r ($arr [0][6]); }
Reply to discussion (solution)
Which master knows to tell, 3Q,
Solve, why the loop does not pass.
Print_r $arr;//Look at $arr what content
Preg_match_all ($preg, $con, $arr); Search content assignment to array
for ($i =0; $i <20; $i + +)//single page intercept
{
Print_r ($arr [0][$i]);
$SS = $arr [2][$i];
Echo $ss;
echo "
";
$opts = Array (
' HTTP ' =>array (
' User_agent ' = ' mozilla/4.0 (compatible; MSIE 5.01; Windows NT 5.0) ",
)
);
$context = Stream_context_create ($opts);
$cons = file_get_contents ("$ss", false, $context);
Print_r ($cons);
Die ();
Title
$preg = ' #
(.*)
#';
Preg_match_all ($preg, $cons, $arr); Search content assignment to array
Print_r ($arr [0][0]);
Content
$preg = ' #
(.*) (.*)
#';
Preg_match_all ($preg, $cons, $arr); Search content assignment to array
Print_r ($arr [0][0]);
echo "
";
Look at the red part above, the name of the array inside and outside the loop is the same, is there no problem?