Re: Question about a text file and foreach

From: Date: Tue, 18 Mar 2003 16:31:11 +0000
Subject: Re: Question about a text file and foreach
References: 1 2  Groups: php.general 
Request: Send a blank email to php-general+get-140136@lists.php.net to get a copy of this message
Jim Greene wrote:
Hi All, I have a text file that has entries like the following: user1:mbox1: user1:mbox2: I basically do: $mboxs = `cat file | grep user1 | cut -d: -f2'; I then want to print out the data in the $mboxs variable (array) I am trying to use foreach but it does not work.. I am assuming the data is not considered an array?
I might be mistaken, but wouldn't the value of $mboxs just be a string containing those characters? If you meant to use backticks to open up a shell pipe, I /think/ that's something you can do only in Perl. You can do it in PHP with the system() function, but it doesn't return an array but rather a string. You can parse the string into an array with string-processing functions. Erik

« previous php.general (#140136) next »