开发者

Tool for displaying text/code ratio in html [closed]

As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance. 开发者_如何学Python Closed 10 years ago.

I am looking for a firefox/firebug plugin (or any OFFLINE tool is OK) to display the ratio of real text/markup.

There are online tools, like http://www.seochat.com/seo-tools/code-to-text-ratio/ and this Firefox plugin: https://addons.mozilla.org/en-US/firefox/addon/150366/ (this is online too).


I made a small script in PHP, the main part is:

$toparse = "htmltext";
$toparse = preg_replace('/(<script.*?>.*?<\/script>|<style.*?>.*?<\/style>|<.*?>|\r|\n|\t)/ms', '', $toparse);  
$toparse = preg_replace('/ +/ms', ' ', $toparse);  
$textlen = strlen($toparse);

There are some calculations after this.
That regex can be shorter, but it works. The only requirement is paired < and >.


$ (URL=www.google.com; echo "scale=2;"`lynx -nolist -dump $URL | wc -c`/`curl -silent $URL | wc -c` | bc)
.06

Though the nice HTML rendering of inputs in links skews the stats a bit.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜