Link to home
Start Free TrialLog in
Avatar of PeterdeB
PeterdeBFlag for Netherlands

asked on

Why is this 'not a valid stream resource?'

Hi Folks,

Check out the code snippet below. When run from within PHP Expert Editor I get the following message for each line it should write into the file url.dat.

Warning: fclose(): 2 is not a valid stream resource in F:\test.php on line 65

Anyone any clues?

Kind regards,

Dweep


$regels= fopen('url.dat', 'w');
 
    for($i=1;$i<(count($urls))+1;$i++) 
             {
		 if (!stristr($urls[$i],$sGoogle))
		         {
		         fputs($regels, $urls[$i])."\n";
		         }
		        fclose($regels);
             }

Open in new window

Avatar of hernst42
hernst42
Flag of Germany image

Try the following code. This might hapen if opening the file failed.
if (($regels= fopen('url.dat', 'w') === false) {
   die('Unable to open "url.dat" for writing');
}

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of dr_dedo
dr_dedo
Flag of Egypt image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of PeterdeB

ASKER

Thanks!
Hernst42 thanks for responding, I tried your code but it didn't solve the problem.
Dr Dedo > I put the fclose outside the loop and that solved the problem.

Kind regards,

Dweep