[PHP] file( ) function
Hi, I am facing some trouble with the file( ) function. I understand that it returns the contents of the file in an array. Also, I am able to print the lines using the echo function. However, whenever I try to compare the contents of an array using strcmp, or ==, the page simply keeps 'loading', instead of printing results. The following is the code that I try: $name = $_POST[filename]; $lines = file($name); $i = 0; $len = sizeof($lines); //echo $i; while($i $len) { //echo $lines[$i]; $temp = $lines[$i]; $temp = trim($temp); //echo $temp; if($temp1 == '--') { echo $i; return $i; } else $i++; } I think that the way the lines of the file are stored in the array may be the problem, but I do not know what I am supposed to change. Any help would be appreciated. Thanks. MM.
Re: [PHP] file( ) function
On 6/8/06, Mayank Maheshwary [EMAIL PROTECTED] wrote: $name = $_POST[filename]; $lines = file($name); $i = 0; $len = sizeof($lines); //echo $i; while($i $len) { //echo $lines[$i]; $temp = $lines[$i]; $temp = trim($temp); //echo $temp; if($temp1 == '--') { This should be $temp, shoudn't it? echo $i; return $i; } else $i++; } Rabin -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] file( ) function
Rabin Vincent [EMAIL PROTECTED] escreveu na mensagem news:[EMAIL PROTECTED] On 6/8/06, Mayank Maheshwary [EMAIL PROTECTED] wrote: $name = $_POST[filename]; $lines = file($name); $i = 0; $len = sizeof($lines); //echo $i; while($i $len) { //echo $lines[$i]; $temp = $lines[$i]; $temp = trim($temp); //echo $temp; if($temp1 == '--') { This should be $temp, shoudn't it? echo $i; return $i; } else Else here´s putting you in loop. $i++; } Rabin -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] file( ) function
Yes, that is actually $temp, not $temp1. However, my problem still remains the same. Several lines in the file contain the exact same string as the one I am comparing. I need their positions in the array so that I can operate on other lines in the file. That is why I am using file( ) instead of other file reader functions. Thanks. MM. $name = $_POST[filename]; $lines = file($name); $i = 0; $len = sizeof($lines); //echo $i; while($i $len) { //echo $lines[$i]; $temp = $lines[$i]; $temp = trim($temp); //echo $temp; if($temp1 == '--') { This should be $temp, shoudn't it? echo $i; return $i; } else $i++; }
Re: [PHP] file function
Joseph Lee wrote: Hi, I tried file() in the following lines: ?php $authFile = file(/tmp/authenticate.txt); print authFile = $authFile; ? However, it only gave me authFile = Array What's wrong with this file function? I tried single quotes, but got the same answer, too. Nothing. You need to read the documentation. What you probably wanted was: print authFile = .implode(,$authFile); or file_get_contents(). -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] file function
I see. Now I know how it works. Thank you, all, for your great help. Joe --- Burhan Khalid [EMAIL PROTECTED] wrote: Joseph Lee wrote: Hi, I tried file() in the following lines: ?php $authFile = file(/tmp/authenticate.txt); print authFile = $authFile; ? However, it only gave me authFile = Array What's wrong with this file function? I tried single quotes, but got the same answer, too. Nothing. You need to read the documentation. What you probably wanted was: print authFile = .implode(,$authFile); or file_get_contents(). -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php __ Yahoo! Mail Stay connected, organized, and protected. Take the tour: http://tour.mail.yahoo.com/mailtour.html -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] file function
On 7/9/05, Joseph Lee [EMAIL PROTECTED] wrote: Hi, I tried file() in the following lines: ?php $authFile = file(/tmp/authenticate.txt); print authFile = $authFile; ? However, it only gave me authFile = Array What's wrong with this file function? I tried single quotes, but got the same answer, too. Trying single quotes should have gotten you authFile = $authFile (without the arrows). There is nothing wrong with the file function. It´s supposed to return an array. If you want it to spit out every element in the array, then perhaps you could use the print_r, var_dump or var_export functions. If you simply want to get the contents of the file into a string, then use file_get_contents(). Thanks, Joe Sell on Yahoo! Auctions – no fees. Bid on great items. http://auctions.yahoo.com/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] file function
Hi, I tried file() in the following lines: ?php $authFile = file(/tmp/authenticate.txt); print authFile = $authFile; ? However, it only gave me authFile = Array What's wrong with this file function? I tried single quotes, but got the same answer, too. Thanks, Joe Sell on Yahoo! Auctions no fees. Bid on great items. http://auctions.yahoo.com/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] file function
Well, it supposed to give you array. http://us2.php.net/manual/en/function.file.php array file ( string filename [, int use_include_path [, resource context]] ) What do you want exactly? Ezra On Fri, 2005-07-08 at 16:34 -0700, Joseph Lee wrote: Hi, I tried file() in the following lines: ?php $authFile = file(/tmp/authenticate.txt); print authFile = $authFile; ? However, it only gave me authFile = Array What's wrong with this file function? I tried single quotes, but got the same answer, too. Thanks, Joe Sell on Yahoo! Auctions – no fees. Bid on great items. http://auctions.yahoo.com/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] File() function and require()
OK, I have a file called page.php that has the following code in it (example but same layout and concept). ?PHP require(membercheck.php); ? html head titlePage Title/title /head body This is the text in the body of the page. /body /html The membercheck.php file contains a login form that is used if a session variable doesn't exist, i.e. the user is not logged in. What happens is when I run file() to read in the contents of page.php it reads in the code that is in the membercheck.php file, and never reads in any code that is in the page.php file. What I would need is a way to read in the contents of the page.php file without reading the membercheck.php file. Better explanation? Mike Tharp Lotus Notes Administrator Herman Miller Inc. [EMAIL PROTECTED]
Re: [PHP] File() function and require()
OK, I have a file called page.php that has the following code in it (example but same layout and concept). ?PHP require(membercheck.php); ? html head titlePage Title/title /head body This is the text in the body of the page. /body /html The membercheck.php file contains a login form that is used if a session variable doesn't exist, i.e. the user is not logged in. What happens is when I run file() to read in the contents of page.php it reads in the code that is in the membercheck.php file, and never reads in any code that is in the page.php file. What I would need is a way to read in the contents of the page.php file without reading the membercheck.php file. Better explanation? Yeah, kind of, but you should show your actual code. I have a feeling your using a command like file('http://www.yourdomain.com/page.php'); to read your data, instead of file('/path/to/file/on/system/htdocs/page.php'); ---John Holmes... -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] File() function and require()
How can I get the file() function to ignore the first three lines of a file it is reading in? I have a site with: ?PHP require(membercheck.php); ? ... rest of file at the top of all the pages to control user logins. The problem is the file() function only reads in the contents of that file, not the rest of the contents after the require statement. Is there a way to tell file() to ignore the first three lines?
RE: [PHP] File() function and require()
How can I get the file() function to ignore the first three lines of a file it is reading in? I have a site with: ?PHP require(membercheck.php); ? ... rest of file at the top of all the pages to control user logins. The problem is the file() function only reads in the contents of that file, not the rest of the contents after the require statement. Is there a way to tell file() to ignore the first three lines? I don't understand what you're asking... it's not making sense. The file() function takes the path to a file and reads it into an array, each element of the array being a line in the file. It could care less if the first three lines were PHP code. It simply reads text and does not evaluate anything (unless you are opening the file with a HTTP connection, i.e. file('http://www...')) Can you show your exact code and what the output is? ---John W. Holmes... PHP Architect - A monthly magazine for PHP Professionals. Get your copy today. http://www.phparch.com/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] file function. please help..
hello. how can i make the file function to put the first 9 lines, in values 01, 02, 03, 04, 05, 06, 07, 08, 09 instead of 1, 2, 3, 4, 5, 6, 7, 8, 9? 10x... -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
Re: [PHP] file function. please help..
huh, explain a little more??? - Original Message - From: Doron [EMAIL PROTECTED] To: [EMAIL PROTECTED] Sent: Saturday, July 07, 2001 6:09 PM Subject: [PHP] file function. please help.. hello. how can i make the file function to put the first 9 lines, in values 01, 02, 03, 04, 05, 06, 07, 08, 09 instead of 1, 2, 3, 4, 5, 6, 7, 8, 9? 10x... -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED] -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
RE: [PHP] file function. please help..
On 07-Jul-01 Doron wrote: hello. how can i make the file function to put the first 9 lines, in values 01, 02, 03, 04, 05, 06, 07, 08, 09 instead of 1, 2, 3, 4, 5, 6, 7, 8, 9? file ? numbers ? ... gotta be the example from the manual (somebody reads it, Halleluja!). Have you looked at printf -or- sprintf ? Regards, -- Don Read [EMAIL PROTECTED] -- It's always darkest before the dawn. So if you are going to steal the neighbor's newspaper, that's the time to do it. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
Re: [PHP] file() function
At the very end: // @readfile(basename(($PHP_SELF . ".comment"))); ? $lines = file(($PHP_SELF . ".comment"))); for ($i = 0; $i 30; $i++){ echo $lines[$i], "BR\n"; } -- Visit the Zend Store at http://www.zend.com/store/ Wanna help me out? Like Music? Buy a CD: http://l-i-e.com/artists.htm Volunteer a little time: http://chatmusic.com/volunteer.htm -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]