Re[3]: [PHP] Having problems with a while loop

From: Date: Thu, 01 Jan 2004 18:12:39 +0000
Subject: Re[3]: [PHP] Having problems with a while loop
References: 1 2 3  Groups: php.general 
Request: Send a blank email to php-general+get-173606@lists.php.net to get a copy of this message
Hello Richard, Thursday, January 1, 2004, 5:56:35 PM, you wrote: RK> Ok I changed it to look this way but it still is not working RK> $filenum="test"; RK> $fpHt = fopen($filenum, "r"); RK> while(feof($fpHt)) { RK> $fpLine = fgets($fpHt,512); RK> $fpLine = trim($fpLine); RK> $fpData = explode(":", $fpLine); RK> $fpData[0] = trim($fpData[0]); RK> echo $fpData[0]; RK> } >>>tester3:$1$09BZpdge$b7TQcsYSsAP1hgiCuCWtS1 >>>tester5:$1$5eq3i75D$XK9QzaS.7bHyWVf4bdyJs/ Save yourself some grief and use the file() function instead. $filename = "test"; $fileData = file($filename); for ($i = 0; $i < count($fileData); $i++) { $output = substr($fileData[$i], 0, strpos($fileData[$i], ":")); echo $output; } strpos will work fine for this assuming the users don't have a : in their username! Otherwise it'll return the first occurrence of it within the string. If it doesn't echo anything out, the file() function failed. Warning: above not tested, just typed direct into this email. But baring obvious syntax errors I might have typo'd, it should work. -- Best regards, Richard mailto:rich@launchcode.co.uk

« previous php.general (#173606) next »