Re: echo'ing a variable and cat'ing text
| From: | John Nichel | Date: | Thu, 02 Mar 2006 18:06:59 +0000 |
| Subject: | Re: echo'ing a variable and cat'ing text | ||
| References: | 1 2 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-231355@lists.php.net to get a copy of this message | ||
John Nichel wrote:
Adam Williams wrote:Oops, should be...I have a file called userlist. I'm trying to read the file, and then echo their name and add @mdah.state.ms.us with it. In the file userlist, it looks like: userabc userdef userxyz and I have the following code: <?php $filename = "userlist"; $fp = fopen($filename, "r") or die ("Couldn't open $filename"); if ($fp) { while (!feof($fp))Well, you're not telling fgets how much to read for one, and I'd do this a different way to begin with... if ( $file = file ( $filename ) ) {{ $thedata = fgets($fp); if ($thedata != "") { echo "$thedata"."@mdah.state.ms.us"; } }fclose($fp); } ?> But when I run it, I get: @mdah.state.ms.ususerabc @mdah.state.ms.ususerdef @mdah.state.ms.ususerxyz and I am expecting to get: userabc@mdah.state.ms.us userdef@mdah.state.ms.us userxyz@mdah.state.ms.us So can someone look at my code and let me know why I'm not getting my expected output?foreach ( $file as $line ) { if ( $file != "" ) {
if ( $line != "" ) {
-- John C. Nichel IV Programmer/System Admin (ÜberGeek) Dot Com Holdings of Buffalo 716.856.9675 jnichel@dotcomholdingsofbuffalo.comecho ( $line . "@mdah.state.ms.us" ); } }} else {echo ( "Couldn't open $filename" );}