Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4125068
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T23:49:18+00:00 2026-05-20T23:49:18+00:00

I have some random HTML layouts that contain important text I would like to

  • 0

I have some random HTML layouts that contain important text I would like to extract. I cannot just strip_tags() as that will leave a bunch of extra junk from the sidebar/footer/header/etc.

I found a method built in Python and I was wondering if there is anything like this in PHP.

The concept is rather simple: use
information about the density of text
vs. HTML code to work out if a line of
text is worth outputting. (This isn’t
a novel idea, but it works!) The basic
process works as follows:

  1. Parse the HTML code and keep track of the number of bytes processed.
  2. Store the text output on a per-line, or per-paragraph basis.
  3. Associate with each text line the number of bytes of HTML required to
    describe it.
  4. Compute the text density of each line by calculating the ratio of text
    t> o bytes.
  5. Then decide if the line is part of the content by using a neural network.

You can get pretty good results just
by checking if the line’s density is
above a fixed threshold (or the
average), but the system makes fewer
mistakes if you use machine learning –
not to mention that it’s easier to
implement!

Update: I started a bounty for an answer that could pull main content from a random HTML template. Since I can’t share the documents I will be using – just pick any random blog sites and try to extract the body text from the layout. Remember that the header, sidebar(s), and footer may contain text also. See the link above for ideas.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-20T23:49:18+00:00Added an answer on May 20, 2026 at 11:49 pm
    • phpQuery is a server-side, chainable, CSS3 selector driven Document Object Model (DOM) API based on jQuery JavaScript Library.

    UPDATE 2

    • DEMO: http://so.lucafilosofi.com/find-important-text-in-arbitrary-html-using-php/
    • tested on a casual blogs list taken from Technorati Top 100 and Best Blogs of 2010
    1. many blogs make use of CMS;
    2. blogs html structure is the same almost the time.
    3. avoid common selectors like #sidebar, #header, #footer, #comments, etc..
    4. avoid any widget by tag name script, iframe
    5. clear well know content like:
      1. /\d+\scomment(?:[s])/im
      2. /(read the rest|read more).*/im
      3. /(?:.*(?:by|post|submitt?)(?:ed)?.*\s(at|am|pm))/im
      4. /[^a-z0-9]+/im

    search for well know classes and ids:

    • typepad.com .entry-content
    • wordpress.org .post-entry .entry .post
    • movabletype.com .post
    • blogger.com .post-body .entry-content
    • drupal.com .content
    • tumblr.com .post
    • squarespace.com .journal-entry-text
    • expressionengine.com .entry
    • gawker.com .post-body

    • Ref: The blog platforms of choice among the top 100 blogs


    $selectors = array('.post-body','.post','.journal-entry-text','.entry-content','.content');
    $doc = phpQuery::newDocumentFile('http://blog.com')->find($selectors)->children('p,div');
    

    search based on common html structure that look like this:

    <div>
    <h1|h2|h3|h4|a />
    <p|div />
    </div>
    

    $doc = phpQuery::newDocumentFile('http://blog.com')->find('h1,h2,h3,h4')->parent()->children('p,div');
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have some code on my PHP powered site that creates a random hash
I have the following snippet where I would like to extract code between the
I have some UI in VB 2005 that looks great in XP Style, but
We have some input data that sometimes appears with &nbsp characters on the end.
I have some classes layed out like this class A { public virtual void
I have some code like this in a winforms app I was writing to
We have some files on our website that users of our software can download.
I want to introduce some random* behavior into an otherwise static html file. I
I have a html page, on this page there are some images, when the
I have a documentFragment with several child nodes containing some .data() added like so:

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.