You are here: Re: Problem w/ reading a txt file. « PHP « IT news, forums, messages
Re: Problem w/ reading a txt file.

Posted by David Robley on 10/13/81 11:27

sub@pudlz.com wrote:

>
> Problem w/ reading a txt file.
>
> The error I get is "Warning: opendir(/home/pudlz/public_html ): failed to
> open dir: No such file or directory "
>
> Here's my code::
>
> $main = file('folders.txt');
> $counter = count($main);
>
> for($i=0;$i<$counter;$i++)
> {
> if ($handle = opendir("$main[$i]"))
> {
> $b=0;
> }
> }
>
>
> It's reading and extra space at the end of all my lines. How do I prevent
> that?

From the docs on file: "...file() returns the file in an array. Each element
of the array corresponds to a line in the file, with the newline still
attached."

So you actually get the text plus a newline character which can be removed
with trim. Simply replace

if ($handle = opendir("$main[$i]"))

with

if ($handle = opendir( trim($main[$i]) ))

You don't need the quotes in opendir in this case.

Cheers
--
David Robley

Put on your seatbelt. I'm gonna try something new.

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация