Solved

reading file from a directory?

Posted on 2002-05-09
2
143 Views
Last Modified: 2006-11-17
hai all,

I wanted to read a dir & choose a particular file.
I wrote as follows:
$dir=dir("/home/ftp/rf_auto");
    while($file=$dir->read()){
     if(substr($file,14,8)=="rf_auto2" && (substr ($file,-12,8)==substr($filename,-12,8))){
     $fcontents1=$file;
     exit();
     }

in this loop I wanted to exit the loop once I select the file($file).
How do I do this?

Thank u,
baska


0
Comment
Question by:baska
2 Comments
 

Author Comment

by:baska
ID: 6998418
//there should be one more closing bracket.
}
//my requirement is,it should not read until end of the dir
//how to implement the condition.

thank u
baska
0
 
LVL 32

Accepted Solution

by:
Batalf earned 50 total points
ID: 6998593
You should use break; instead of exit;

Exit; is used to exit the script, break is used to break out of a loop:

$dir=dir("/home/ftp/rf_auto");
   while($file=$dir->read()){
    if(substr($file,14,8)=="rf_auto2" && (substr ($file,-12,8)==substr($filename,-12,8))){
    $fcontents1=$file;
    break;
    }
}
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Popularity Can Be Measured Sometimes we deal with questions of popularity, and we need a way to collect opinions from our clients.  This article shows a simple teaching example of how we might elect a favorite color by letting our clients vote for …
Foreword (July, 2015) Since I first wrote this article, years ago, a great many more people have begun using the internet.  They are coming online from every part of the globe, learning, reading, shopping and spending money at an ever-increasing ra…
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…

743 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now