SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Enthusiast
    Join Date
    Jul 2000
    Posts
    32
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I have the following code in my script:

    $index = @file('index.txt');
    for ($i=0; $i<count($index); $i++) { ... ;}

    But the problem is that if the file index.txt does not exist,
    count($index) will still get the value 1! So the for statement
    doesn't work so well.

    My question is, is this a PHP error, is it my error, or should
    count($index) be 1?

    Please let me know!

  2. #2
    SitePoint Author Kevin Yank's Avatar
    Join Date
    Apr 2000
    Location
    Melbourne, Australia
    Posts
    2,571
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Just work around the problem by checking for the file's existence:

    Code:
    if (file_exists('index.txt')) {
      ... your code here ...
    }
    Kevin Yank
    CTO, sitepoint.com
    I wrote: Simply JavaScript | BYO PHP/MySQL | Tech Times | Editize
    Baby’s got back—a hard back, that is: The Ultimate CSS Reference


Bookmarks

Posting Permissions

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