RE: [PHP] Where's the error?
Thanks heaps for your help I really appreciate it. I have made the changes you suggested but now I only get a blank screen. These are more general hints on ways to solve the problem yourself. function getmydate($hit) { $single = explode ( ,$hit); return $single[3].$single[4]; } What happens if you feed this function a designated string that you explicitly provide. ie. Define $string to be a line of data you'd like get date info on and then call the function. If you get the right thing you know your function is doing what you expected. $filename = (combined_log); //fopen ($filename, r); $fcontents = file($filename); $limit = 1; for ($i = 0; $i = $limit; $i++) { $line = $fcontents[i]; Try echo'ing $line to make sure you actually had something happen. if (!empty($line)) { $currentdate = getmydate($line); echo $currentdate; } } Work up to the whole solution if you find things not working like you'd expect. CYA, Dave -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Where's the error?
On Mon, 2002-05-13 at 19:32, Josh Edwards wrote: This is meant to grab a date out of a log file from the first line of the array but I'm getting a parse error on line 13. Any ideas? function getdate($hit) There is already a PHP function named 'getdate()'; you'll need another name here. { $single = explode ( ,$hit); return $single[3].$single[4]; } $filename = (combined_log); fopen ($filename, r); fopen() is meaningless here; you don't need to use it with file(). $fcontents = file($filename); $limit = 1; for ($i = 0; $i = $limit; $i++) { $line = $fcontents[i]; if ($line! = ) The above line should be: if ($line != ) ...but you may be better off with if (!empty($line)) ...or... if (strlen($line) 0) ...or something like that. Hope this helps, Torben { $currentdate = getdate($line); echo $currentdate; } } -- Torben Wilson [EMAIL PROTECTED] http://www.thebuttlesschaps.com http://www.hybrid17.com http://www.inflatableeye.com +1.604.709.0506 -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Where's the error?
Thanks heaps for your help I really appreciate it. I have made the changes you suggested but now I only get a blank screen. function getmydate($hit) { $single = explode ( ,$hit); return $single[3].$single[4]; } $filename = (combined_log); //fopen ($filename, r); $fcontents = file($filename); $limit = 1; for ($i = 0; $i = $limit; $i++) { $line = $fcontents[i]; if (!empty($line)) { $currentdate = getmydate($line); echo $currentdate; } } -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Where's the error?
On Mon, 2002-05-13 at 20:01, Josh Edwards wrote: Thanks heaps for your help I really appreciate it. I have made the changes you suggested but now I only get a blank screen. function getmydate($hit) { $single = explode ( ,$hit); return $single[3].$single[4]; } $filename = (combined_log); //fopen ($filename, r); $fcontents = file($filename); $limit = 1; for ($i = 0; $i = $limit; $i++) { $line = $fcontents[i]; if (!empty($line)) { $currentdate = getmydate($line); echo $currentdate; } } Things to check: o Put 'error_reporting(E_ALL);' as the first line of your script. o Are you sure it's reading the file? Try 'print_r($fcontents);' after the file() call. That might get you a little farther. Otherwise post a few representative lines from combined_log; otherwise we won't have any real data to work with. -- Torben Wilson [EMAIL PROTECTED] http://www.thebuttlesschaps.com http://www.hybrid17.com http://www.inflatableeye.com +1.604.709.0506 -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] Where's the error?
$line = $fcontents[i]; should read $line = $fcontents[$i]; -Original Message- From: Josh Edwards [mailto:[EMAIL PROTECTED]] Sent: Tuesday, May 14, 2002 1:02 PM To: [EMAIL PROTECTED] Subject: Re: [PHP] Where's the error? Thanks heaps for your help I really appreciate it. I have made the changes you suggested but now I only get a blank screen. function getmydate($hit) { $single = explode ( ,$hit); return $single[3].$single[4]; } $filename = (combined_log); //fopen ($filename, r); $fcontents = file($filename); $limit = 1; for ($i = 0; $i = $limit; $i++) { $line = $fcontents[i]; if (!empty($line)) { $currentdate = getmydate($line); echo $currentdate; } } -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Where's the error?
I put 'print_r($fcontents);' in and it outputted the array of my log file so I'm not sure what's wrong. Here's a section of the log file. I'm trying to get the date of the first access and the last access. 203.29.154.13 - - [08/May/2002:21:21:22 +1000] GET /A1.html HTTP/1.1 304 - - Mozilla/4.0 (compatible; MSIE 5.5; Windows 98) 203.29.154.13 - - [09/May/2002:21:21:23 +1000] GET /A1.html HTTP/1.1 304 - - Mozilla/4.0 (compatible; MSIE 5.5; Windows 98) 203.29.154.13 - - [10/May/2002:21:21:24 +1000] GET /A1.html HTTP/1.1 304 - - Mozilla/4.0 (compatible; MSIE 5.5; Windows 98) Regards Josh Lars Torben Wilson [EMAIL PROTECTED] wrote in message 1021345553.886.133.camel@ali">news:1021345553.886.133.camel@ali... On Mon, 2002-05-13 at 20:01, Josh Edwards wrote: Thanks heaps for your help I really appreciate it. I have made the changes you suggested but now I only get a blank screen. function getmydate($hit) { $single = explode ( ,$hit); return $single[3].$single[4]; } $filename = (combined_log); //fopen ($filename, r); $fcontents = file($filename); $limit = 1; for ($i = 0; $i = $limit; $i++) { $line = $fcontents[i]; if (!empty($line)) { $currentdate = getmydate($line); echo $currentdate; } } Things to check: o Put 'error_reporting(E_ALL);' as the first line of your script. o Are you sure it's reading the file? Try 'print_r($fcontents);' after the file() call. That might get you a little farther. Otherwise post a few representative lines from combined_log; otherwise we won't have any real data to work with. -- Torben Wilson [EMAIL PROTECTED] http://www.thebuttlesschaps.com http://www.hybrid17.com http://www.inflatableeye.com +1.604.709.0506 -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Where's the error?
Fixed !!! It should be $line = $fcontents[$i]; not $line = $fcontents[i]; Would you know the syntax to get the the last date? ie $lastdate = getmydate($line[(count($line))]); echo $lastdate; -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] Where's the error?
that'll prob. be: $lastdate = getmydate($fcontents[count($fcontents)-1]); remember that array indexes start at 0, hence the -1 bit -Original Message- From: Josh Edwards [mailto:[EMAIL PROTECTED]] Sent: Tuesday, May 14, 2002 1:33 PM To: [EMAIL PROTECTED] Subject: Re: [PHP] Where's the error? Fixed !!! It should be $line = $fcontents[$i]; not $line = $fcontents[i]; Would you know the syntax to get the the last date? ie $lastdate = getmydate($line[(count($line))]); echo $lastdate; -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php