Keith Devens .com |
Friday, September 3, 2010 | ![]() |
| The status is *not* quo. – Dr. Horrible | ||
|
| ← Jim's Inklog design | Line count for code on my site → |

Joe Grossberg (http://www.joegrossberg.com) wrote:
Keith (http://keithdevens.com/) wrote:
Why would you want that information?
I was just interested in seeing how much code I'm including on each page execution.
Also, shouldn't you...
Well... that's why I called it "quick and dirty".
I could strip out code-less lines, but even after that you're always going to have some variation - some people's code is more dense than others, even coming down to simple variations such as:
if(foo)
{
}
else
{
}
vs.
if(foo){
}else{
}
though also including other aspects of code style. In any case, it's probably really easy to strip code-less lines with some quick regular expressions without making it much less quick or dirty, so I may do that if I need this again in the future.
Jay (http://hidemein.com) wrote:
Hi there Keith I'm a bit of a novice with PHP and I'm tiring to script a code to analyze the number of characters in the source of a html document. The trouble is there are no (only at the top) <some html statement> present as the page is ASCII text in both the source and browser zones.
I'm tiring to set the script to count chars from predesignated lines eg: count "some ASCII char" from (line 62 col 32) to (line 62 first space)as an example.
Question: Are you fetching <> statements form html tags for the code above and if (or if not) how does one retrieve the character count without the fetch <some html statement> but with a line (y) col (x) coordinate statement instead?.
Jay (http://hidemein.com) wrote:
Keith @ http://keithdevens.com
Hi there again I searched around for a starting point and found the following. It's at least solved the (line 62 first space) problem as it only count the characters in the string and not it's spaces.
As you notice it can handle in Unicode fonts which is a bonus - echo unichar("áá b"); and echo unichar("as ñ"); although the line count in the document is standard ASCII. I've also deliberately placed spaces in the strings to test if it would nullify these in the results, here's where I'm at:
________________________________
<?php
function unichar($string) {
$two= strtolower(str_replace(' ', '', $string));
$res = count(count_chars($two, 1));
return $res;
}
echo unichar("áá b");
print (',');
echo unichar("as ñ");
print (',');
echo unichar("adddd b");
print (',');
echo unichar("sssa b");
print (',');
echo unichar("as b");
print (',');
echo unichar("asewewqw b");
print (',');
echo unichar("astrrtrtewtwt b");
print (',');
echo unichar("asr b");
print (',');
echo unichar("wrtwt wrtwtw wrtwrt rtw rt w as b");
print (',');
echo unichar("abc ");
_______________________________
outputs:
2,3,3,3,3,6,7,4,6,3
_______________________________
What I think I need to do is somehow place ($ ??) into the strings to call for the specific lines from the page source of the document in question, and I'm guessing with the CURL function or similar retrieve (fetch) method. As I stated before I'm only a novice but I've got the basic gist of PHP scripting.
Any advice or pointers in the right direction would be most grateful, cheers!
PS: this is a script for personal use (non profit) and is engineering, analytical based for the purpose of automating - calculating information dynamics form a text/html document.
Feel free to post a comment below. Please see my comment policy.
Formatting Rules (No HTML):
Generated in about 0.159s.
(Used 8 db queries)
Why would you want that information?
Also, shouldn't you exclude lines that don't contain any code, such as multi-line comments and blank lines?