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 571243
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T13:29:12+00:00 2026-05-13T13:29:12+00:00

I have an external HTML source that I want to scrape and either transform

  • 0

I have an external HTML source that I want to scrape and either transform into a local XML file or add to a MySQL DB.

The external source is mostly normalized and (somewhat) semantic, so that all I need to do is use XPATH to get all td content or all li content, etc. The problem is that occasionally these items use <strong> or <b> or <i> tags to style the elements I need.

This is technically semantic, since the point is to add emphasis to the specific text, and the developer might want to use CSS that isn’t the browser default.

The problem is that the actual content I am trying to grab is considered a child of this inline element, so that PHP extensions like simplexml or DOMDocument and DOMNode treat them as such. For example:

<table>
<tr><td>Thing 1</td><td>Thing 2</td></tr>
<tr><td>Thing 3</td><td>Thing 4</td></tr>
<tr><td><strong>Thing 5</strong></td><td><strong>Thing 6</strong></td></tr>
</table>

Will result in:

 [table] =>
    [tr] =>
        [td] => Thing 1
        [td] => Thing 2
    [tr] =>
        [td] => Thing 3
        [td] => Thing 4
    [tr] =>
        [td] => 
            [strong] => Thing 5
        [td] => 
            [strong] => Thing 6

Obviously the above is not quite what simplexml returns, but the above reflects the general problem.

So is there a way, using either a parameter already built into DOMDocument or using an extra sophisticated XPath query to get the contents of the td element with any children (if there are any) stripped of their descendant status and all content treated as the text of the queried element?

Right now, the only solutions I have are to either:

a) have a foreach loop that checks each result, like:

$result_text = ($result -> strong) ? $result - strong : $result;

b) using regex to strip any <strong> tags out of the HTML string before importing it into any pre-built classes like simplexml or DOMDocument.

  • 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-13T13:29:12+00:00Added an answer on May 13, 2026 at 1:29 pm

    Can’t you just use strip_tags() to remove the extra markup?

    $table = simplexml_load_string(
        '<table>
            <tr><td>Thing 1</td><td>Thing 2</td></tr>
            <tr><td>Thing 3</td><td>Thing 4</td></tr>
            <tr><td><strong>Thing 5</strong></td><td><strong>Thing 6</strong></td></tr>
        </table>'
    );
    
    foreach ($table->xpath('//td') as $td)
    {
        $content = strip_tags($td->asXML());
        echo $content, "\n";
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a page that loads an external HTML page into an iFrame. There
I have some code that pulls HTML from an external source: $doc = new
Lets say i have an external html page and I want to append text
I have an external file in php, outputed as json format I want the
I have an Android application which grabs some data from an external XML source.
Can we have external NoScript file? If javascript is not avaialbe i want to
I have a bunch of HTML markup coming from an external source, and it
I have a dynamic webpage that includes an iFrame where external html code is
I have external html5 canvas that you can paint on some lines using your
I have an external setting file which has some nodes holiding attribute values of

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.