FRIHOST FORUMS SEARCH FAQ TOS BLOGS COMPETITIONS
You are invited to Log in or Register a free Frihost Account!


Line Counter





DanielXP
I have a new members area and it saves it into a text file .txt

and what i want is a script to count the lines of this .txt so i will be able to display the ammount of registered users, its a line per user.

Any one think theres a way of this?
cafefort
Hi DanielXP,

Well, I'd suggest you this solution:

Code:
<?php

//fonction to read the content of a file
function file_read($file)
{
  $id = fopen($file,"r");
  $lect = fread($id,filesize($file));
  $k = fclose($id);
  return ($lect);
}

//read the content of the users file
$file_content =  file_read("users.txt);

//new line is different from linux and windoz
$file_content=str_replace("\r\n","\n",$file_content);

//explode that string according to the
// new line caracters
$users_array=explode("\n",$file_content);

$ucount = count($users_array);

echo "users count is $ucount ";

?>


That's it.

Hope this helps Smile
Marston
That function isn't necessary.
cafefort
Yeah! not necessary...

That's how I code, If it's not OOP it's procedural.
I guess DanielXP may wish to reuse this function elsewhere
in his programs and after all, I've written that code without
any preparation and I tried to comment it in an educational way.

Hope this helps anyway.

Thanks.
DanielXP
I keep get get this error.


Code:
Warning: Unexpected character in input: '\' (ASCII=92) state=1 in /home/www/scripting4habbo.com/V3/count.php on line 16

Parse error: parse error, unexpected T_STRING in /home/www/scripting4habbo.com/V3/count.php on line 16
DanielXP
This font is horriable (the colours)

er what does this error mean?
Related topics
Counter strike
Favourite game? (OFFICIAL THREAD)
PHP Write to line
script backup database
There's One Born Every Minute
Blonde Fishing Line
Tutorial: PHP Installed Modules Dynamic Reference Tool
gazza withdraw
Frankfurt Motor Show, 2005
Need script
Counter Strike website!
Counter
could use some help..simple one line issue
Simple, simple HIT counter
Reply to topic    Frihost Forum Index -> Scripting -> Php and MySQL

FRIHOST HOME | FAQ | TOS | ABOUT US | CONTACT US | SITE MAP
© 2005-2011 Frihost, forums powered by phpBB.