Results 1 to 5 of 5

Thread: Ignore error and continue

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Jan 2002
    Posts
    259

    Ignore error and continue

    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 ?

  2. #2
    Member
    Join Date
    Jan 2002
    Location
    India
    Posts
    50
    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.

  3. #3
    Member
    Join Date
    Jun 1999
    Posts
    38
    or you can say

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

    or just use @
    I swear you guys rip on me 13 or 14 more times, i'm outta here...

  4. #4

    Thread Starter
    Hyperactive Member
    Join Date
    Jan 2002
    Posts
    259

    Thanks

    Thank you Very much hardcoder & Howard Stern

  5. #5
    scoutt
    Guest
    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.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width