I'm really stuck. Please help me.
Posted: Wed May 14, 2003 2:08 pm
I have the script below which looks for all the links on a string($new_str) and try to open each link (in the foreach statement) to get it's content.
I'm stuck on getting each url's content. Please help me.
The problem is that it only get the first URL's content, when it tries to move on to the next URL, it stops.
I'm stuck on getting each url's content. Please help me.
Code: Select all
<?php
$new_str =
"
<a href="http://www1.folha.uol.com.br/folha/brasil/ult96u49003.shtml">Link 1</a><br>
<a href="http://www1.folha.uol.com.br/folha/mundo/ult94u56767.shtml">Link 2</a><br>
<a href="http://www1.folha.uol.com.br/folha/dinheiro/ult91u67128.shtml">Link 3</a><br>
<a href="http://www1.folha.uol.com.br/folha/cotidiano/ult95u74774.shtml">Link 4</a><br>
<a href="http://www1.folha.uol.com.br/folha/esporte/ult92u59688.shtml">Link 5</a><br>
<a href="http://www1.folha.uol.com.br/folha/ilustrada/ult90u32944.shtml">Link 6</a><br>
<a href="http://www1.folha.uol.com.br/folha/informatica/ult124u12907.shtml">Link 7</a><br>
<a href="http://www1.folha.uol.com.br/folha/ciencia/ult306u9093.shtml">Link 8</a><br>
<a href="http://www1.folha.uol.com.br/folha/educacao/ult305u12840.shtml">Link 9</a>
";
//Let's say I don't know how many links the string has, so I do this
$abc = preg_match_all("/<a.+?hrefs*=s*([']?)(.+?)*?>/is", $new_str, $match_l);
for($aa=0;$aa<=$abc;$aa++) {
foreach($match_l as $value) {
//Here I extract the "junk" to have only the URL
$str_url = eregi_replace(""","",$value[$aa]);
$str_url = eregi_replace("<a href=","",$str_url);
$str_url = eregi_replace(">","",$str_url);
print "$str_url<br>";
//Here I try to open the URL to get it's content
if(!($File=fopen($str_url,"r")))
{
echo "There was a problem fetching the content requested.";
exit;
}
while(!feof($File))
{
$Line.=fgets($File,2000055);
}
fclose($File);
$startN="<!--NOTICIA-->";
$endN="<!--/NOTICIA-->";
$start_positionN=strpos($Line, $startN);
$end_positionN=strpos($Line, $endN)+strlen($endN);
$lengthN=$end_positionN-$start_positionN;
$Line=substr($Line, $start_positionN, $lengthN);
echo "<br><br>$Line<BR><BR>";
}
}
?>