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

  • SEARCH
  • Home
  • 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 8328311
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T01:23:53+00:00 2026-06-09T01:23:53+00:00

I’m parsing information from a very long HTML table; right now the code I’m

  • 0

I’m parsing information from a very long HTML table; right now the code I’m using parses using the DOMDocument, DOMElement (etc) classes. I wanted to do a performance test running the current method against Regex’ing the information out of the table but I can’t get the right expression.

An HTML row of the table looks like this:

<tr><td>   JON SMITH     </td><td> 2000-09-29 </td></tr>

And the expression I’ve been attempting looks something like this:

/(?:<td>([a-zA-Z\s]*?)<\/td><td>([0-9-\s]*?)<\/td>)/

The issue with the above expression is that it’s returning the entire row contents and not just the inner column contents. Ideally the preg_match_all array results would be name, date, name, date etc.

Is this a reasonable thing to do, or should I stick with the DOM technique? If it is reasonable, could someone lend a hand with the regex?

Thanks!

EDIT: In case anyone stumbles upon this in the future, the RegEx solution has WAY better performance than using the DOM classes; in my situation it’s the difference between seconds and minutes.

  • 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-06-09T01:23:56+00:00Added an answer on June 9, 2026 at 1:23 am

    use preg_match_all() and pass the third parameter with the array to fill and the fourth parameter PREG_SET_ORDER.

    preg_match_all("/(?:<td>([a-zA-Z\s]*?)<\/td><td>([0-9-\s]*?)<\/td>)/", $html, $matches, PREG_SET_ORDER);
    

    The result array should be like this :

    $matches => array(
       [0] => array(
          [0] => '<td>   JON SMITH     </td><td> 2000-09-29 </td>',
          [1] => '   JON SMITH     ',
          [2] => ' 2000-09-29 '
       ),
       [1] => array(
          [0] => '<td>   JACK BOLD     </td><td> 2000-10-20 </td>',
          [1] => '   JACK BOLD     ',
          [2] => ' 2000-10-20 '
       ),
       ...
    );
    

    Please refer to preg_match_all() documentation.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm new to using the Perl treebuilder module for HTML parsing and can't figure
link Im having trouble converting the html entites into html characters, (&# 8217;) i
this is what i have right now Drawing an RSS feed into the php,
I have this code to decode numeric html entities to the UTF8 equivalent character.
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I have a view passing on information from a database: def serve_article(request, id): served_article
I have thousands of HTML files to process using Groovy/Java and I need to
That's pretty much it. I'm using Nokogiri to scrape a web page what has
For some reason, after submitting a string like this Jack’s Spindle from a text

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.