thibo1025 Posted April 23, 2006 Share Posted April 23, 2006 how with a php tag show the number of coding lines that are in an other sheet?It is rather important for me to know this. If you could help me out for this it would be nice thank you Link to comment Share on other sites More sharing options...
Jack McKalling Posted April 23, 2006 Share Posted April 23, 2006 For what sort of program do you want to use this information?If you mean the written lines in one file, they can be count from within an editor, the filesize can be looked up by FTP instructions, but why the lines count?Do you have some sory of simple database built, called a flat file, from which you like to know how many entries it consists of? Or something else? :)There is a way of counting the lines by actual reasonable advanced coding, but that may not be what you want - after all there are better ways to store your information else than in a flat file Link to comment Share on other sites More sharing options...
justsomeguy Posted April 23, 2006 Share Posted April 23, 2006 You can open the file and count the number of line breaks if you want. Or if you only want to know how many lines there are of text you can exclude all of the sequential line breaks. Link to comment Share on other sites More sharing options...
thibo1025 Posted April 24, 2006 Author Share Posted April 24, 2006 Actually what I want is simpler than that (well I think). What I want to count is the number of lines in the source of the file for example <html><head><title></tilte></head><body><p>hello</p></body></html> contains 9 or 10 lines and that is the number I want to be able to show. Link to comment Share on other sites More sharing options...
justsomeguy Posted April 24, 2006 Share Posted April 24, 2006 Right - so you count the number of line breaks, and add one.This file: line1\nline2\nline3 Has 2 line breaks, and there are three lines. Count the number of line breaks. You can explode the string on a newline and count the number of array elements, use substr_count to determine how many there are, or just walk through the string and count up the newlines. However you want to accomplish it, that's what you do, I'm telling you. Link to comment Share on other sites More sharing options...
pulpfiction Posted April 24, 2006 Share Posted April 24, 2006 Count the number of lines in a text filehttp://www.totallyphp.co.uk/code/count_the...a_text_file.htmcheck out the link.This is for a text file, but i guess will work for other files too.. Link to comment Share on other sites More sharing options...
Chocolate570 Posted April 24, 2006 Share Posted April 24, 2006 So you're doing this with an external file? Link to comment Share on other sites More sharing options...
Little Goat Posted April 24, 2006 Share Posted April 24, 2006 <?php$read=file("yourfilename.htm")$lines=count($read)echo $lines?> I think that will work. LG Link to comment Share on other sites More sharing options...
thibo1025 Posted April 25, 2006 Author Share Posted April 25, 2006 ok this seams perfect only can I do instead <?php$read = "yourfilename.htm";$count = count($read);$lines = $count - "1";echo "There are $lines lines in $read.";?> because it is counting one line to much... so can you tell me if this is the way to fix it? Link to comment Share on other sites More sharing options...
justsomeguy Posted April 25, 2006 Share Posted April 25, 2006 That's fine, but you don't need the 1 in quotes. Link to comment Share on other sites More sharing options...
Little Goat Posted April 25, 2006 Share Posted April 25, 2006 don't forget the file() function.LG Link to comment Share on other sites More sharing options...
justsomeguy Posted April 25, 2006 Share Posted April 25, 2006 Right. This should work: $lines = count(file($fname)) - 1; Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now