PDA

Click to See Complete Forum and Search --> : Ignore error and continue


prokhaled
Feb 21st, 2002, 02:53 PM
in this example it will open 1.txt , 2.txt and 3.txt

for ($i = 1; $i <= 3; $i++)
{

$FILE=fopen("$i.txt","r");
$Find=fgets($FILE,4096);
fclose($FILE);

}


the problem:
1.txt file is not found now so it give me error message. I want to ignore this error message and continue the program without give me any error message . how can I do that ?

hardcoder
Feb 21st, 2002, 08:43 PM
if you want to turn off error msgs completely for this script, write the following before the code:

error_reporting(0);

inside a PHP block of course!

if youjust want to bypass errors from certain functions, precede those fns with '@' like:

@fopen(whatever....);

HTH.

Howard Stern
Feb 23rd, 2002, 09:14 AM
or you can say

if(file_exists("$i.txt")) {
fopen...
}

or just use @

prokhaled
Feb 23rd, 2002, 01:53 PM
Thank you Very much hardcoder & Howard Stern

scoutt
Feb 25th, 2002, 02:27 PM
or you can start i as 2

for ($i = 2; $i <= 3; $i++)
{

$FILE=fopen("$i.txt","r");
$Find=fgets($FILE,4096);
fclose($FILE);

}

but will only stop the error for 1.txt.