PHP to Calculate Text/HTML Ratio

by 9 replies
13
Hi,

I am currently building an online application using PHP, where I need to calculate the text to html ratio of a website.

Anyone has a good PHP class or script to calculate this?

Thanks!
#programming #calculate #php #ratio #text or html
  • I see a few examples of use after doing a search. I don't see code examples though.

    I did find
    javascript:alert('text/html = '+(b=document.body).innerText.length/b.innerHTML.length);void(0);

    in a comment at Search Engine Optimization: Textarea and HTML comments - CodingForums.com
  • Unfortunately I'm not proficient in Javascript :/

    I don't want to cut the possibility of doing Javascript - but I need a better tutorial in order to implement it ...

    Anyone with a better solution?
    • [1] reply
    • What exactly do you mean by "text to HTML ratio"?
      • [1] reply
  • Banned
    [DELETED]
  • I am currently building a tool to analyse this as it is an important factor for SEO.

    jassmee, I am not looking for the actual size in pixels - I need the ratio of html characters to content characters.

    KirkMcD is the one who got the closest ... thought there might be something ready for use out there though!
  • You can try something below, if your real intention is to find out keyword density.

    $content = strip_tags($html_content);
    $len = strlen($content);

    foreach($keyword_array as $keyword)
    {
    $found = substr_count($content, $keyword);
    $keyword_density[$keyword] = ($found / $content);
    }

    Well, I really don't think keyword density is really important now, since Google just changed its SEO algo again.
  • I was searching for Content/HTML ratio - followed KirkMcD's suggestion and it worked.

    Yeps, keyword density is next - traderookie's code gave errors. Will see how to go about it.

    I am sure both factors still affect Google's algorithm.

Next Topics on Trending Feed