Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Fopen working with array error!

Status
Not open for further replies.

fireburner69

Programmer
Joined
Aug 22, 2002
Messages
108
Location
GR
Ok I have a db full with html links!
First I create a query and but all the links into array
$links[$i] and everytime $i++;
SO I have the array with all the links
And then I make a loop in order to fopen all the links which is something like that
//Start collecting proccess
$w=0;
while ($i > $w) {
$OpenFile = fopen "$links[$w]", "r");
$RetrieveFile = fread($OpenFile, 200000);
$GrabData = eregi(&quot;<title>(.*)</title>&quot;, $RetrieveFile, $DataPrint);
fclose($OpenFile);
echo $DataPrint[$w].&quot;<br>&quot;;
$w++;
}


Everything goes fine until this msgs comes up

Warning: fopen(&quot; &quot;, &quot;r&quot;) - Success in cmeta.php on line 16

Warning: Supplied argument is not a valid File-Handle resource in cmeta.php on line 17

Warning: Supplied argument is not a valid File-Handle resource in cmeta.php on line 20


After that I said ok lets see that. I replace the $links[$w] with the url and the space after that if you notice that and It works fine!

Any ideas why it does that? and How can I over pass it?

I just need to collect from 12000 Sites the <title> So this is imposible to do it manual :)) any ideas?

Thanx in advance! :)
 
try this:
while ($i > $w) {
$OpenFile = fopen ($links[$w], &quot;r&quot;) or die(&quot;Error&quot;);
$RetrieveFile = fread($OpenFile, 200000) or die(&quot;Error1&quot;);
$GrabData = eregi(&quot;<title>(.*)</title>&quot;, $RetrieveFile, $DataPrint);
fclose($OpenFile);
echo $DataPrint[$w].&quot;<br>&quot;;
$w++;
}


the die stmt can help u to locate the error...

Known is handfull, Unknown is worldfull
 
This one comes up with
Error msg
so this is located in the 1st cmd
$OpenFile = fopen ($links[$w], &quot;r&quot;) or die(&quot;Error&quot;);


But when I just write the address instead of $links[$w] works fine :)

 
You are creating overhead by sticking the records into an array and using counters. You can avoid that extra code and work:

1. Make your SQL query and obtain a resource identifier ($result).
Code:
$result = mysql_query($SQL) or die(mysql_error());

2. Loop through the returned records:
Code:
while($row = mysql_fetch_assoc($result)){
  # now do the fopen stuff
   $fp = fopen($row['columnNameForLink'],'r') or die(&quot;Can't open');
}

Also take into consideration:
If PHP has decided that filename specifies a registered protocol, and that protocol is registered as a network URL, PHP will check to make sure that allow_url_fopen is enabled. If it is switched off, PHP will emit a warning and the fopen call will fail.
 
try also this:
$OpenFile = fopen ($links[$w], &quot;r&quot;) or die($links[$w]);


Known is handfull, Unknown is worldfull
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top