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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T13:42:24+00:00 2026-05-19T13:42:24+00:00

I just started to use PHP Simple HTML DOM Parser . Now I’m trying

  • 0

I just started to use PHP Simple HTML DOM Parser.

Now I’m trying to extract all elements surrounded with a <b>-tag inclduing </b> from an exsiting HTML document. This works fine with

foreach($html->find('b') as $q)
    echo $q;

How can I achieve to show up only elements surrounded with the <b>,</b>-tags followed by a <span class="marked">?

Update:
I’ve used firebug to get the css path for the elements. Now it looks like this:

foreach ($html->find('html body div#wrapper table.desc tbody tr td div span.marked') as $x)
    foreach ($x->find('html body div#wrapper table.desc tbody tr td table.split tbody tr td b') as $d)
        echo $d;

But it won’t work… Any Ideas?

Update:

To clarify my question here a sample tr of the document with starting table and ending table tags.

<table width="100%" border="0" cellspacing="0" cellpadding="0" class="desc">
    <tr>
        <th width="25%" scope="col"><div align="center">1</div></th>
        <th width="50" scope="col"><div align="center">2</div></th>
        <th width="10%" scope="col"><div align="center">3</div></th>
        <th width="15%" scope="col"><div align="center">4</div></th>
    </tr>
    <tr>
        <td valign="top" bgcolor="#E9E9E9"><div style="text-align: center; font-weight: bold; margin-top: 2px"> 1 </div></td>
        <td>
            <table width="100%" border="0" cellspacing="0" cellpadding="0" class="split">  <tr>
                    <td>
                        <b> element to extract</b></td>
                </tr>
                <tr>
                    <td>
                        <table width="100%" border="0" cellspacing="0" cellpadding="0" class="split">  <tr>
                                <td width="15px" valign="top">&nbsp;</td>
                                <td width="15px" valign="top">  
                                    <div style="background-color:green ;color:#FFFFFF; text-align:center;padding-bottom: 1px">
                                        1
                                    </div>
                                </td>
                                <td>
                                    abed
                                </td>
                            </tr>
                            <tr>
                                <td width="15px" valign="top">&nbsp;</td>
                                <td width="15px" valign="top">  
                                    <div style="background-color:green ;color:#FFFFFF; text-align:center;padding-bottom: 1px">
                                        2
                                    </div>
                                </td>
                                <td>
                                    ddee
                                </td>
                            </tr>
                            <tr>
                                <td width="15px" valign="top">&nbsp;</td>
                                <td width="15px" valign="top">  
                                    <div style="background-color:green ;color:#FFFFFF; text-align:center;padding-bottom: 1px">
                                        3
                                    </div>
                                </td>
                                <td>
                                    xdef
                                </td>
                            </tr>
                            <tr>
                                <td width="15px" valign="top">&nbsp;</td>
                                <td width="15px" valign="top">
                                    <div style="background-color:green ;color:#FFFFFF; text-align:center;padding-bottom: 1px">
                                        4
                                    </div>
                                </td>
                                <td>
                                    abbcc
                                </td>
                            </tr>
                            <tr>
                                <td width="15px" valign="top">&nbsp;</td>
                                <td width="15px" valign="top">  
                                    <div style="background-color:green ;color:#FFFFFF; text-align:center;padding-bottom: 1px">
                                        5
                                    </div>
                                </td>
                                <td>
                                    ab
                                </td>
                            </tr>
                            <tr>
                                <td width="15px" valign="top">&nbsp;</td>
                                <td width="15px" valign="top">  
                                    <div style="background-color:green ;color:#FFFFFF; text-align:center;padding-bottom: 1px">
                                        6
                                    </div>
                                </td>
                                <td>
                                    e1
                                </td>
                            </tr>
                        </table>
                    </td>
                </tr>
            </table>
        </td>
        <td valign="top"><div style="text-align: center"> <span class="marked">marked</span> </div></td>
        <td valign="top"><div style="text-align: center">  </div></td>
    </tr>
</table>
  • 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-19T13:42:25+00:00Added an answer on May 19, 2026 at 1:42 pm

    Try the following CSS selector

    b > span.marked
    

    That would return the span though, so you probably have to do $e->parent() to get to the b element.

    Also see Best Methods to parse HTML for alternatives to SimpleHtmlDom


    Edit after update:

    Your browser will modify the DOM. If you look at your markup, you will see that there is no tbody elements. Yet Firebug gives you

    html body div#wrapper table.desc tbody tr td div span.marked'
    html body div#wrapper table.desc tbody tr td table.split tbody tr td b'
    

    Also, your question does not match the queries. You asked how to find

    elements surrounded with the <b>,</b>-tags followed by a <span class="marked">

    That can be read to either mean

    <b><span class="marked">foo</span></b>
    

    or

    <b><element>foo</element></b><span class="marked">foo</span>
    

    For that first use the child combinator I have shown earlier. For the second, use the adjacent sibling combinator

    b + span.marked
    

    to get the span and then use $e->prev_sibling() to return the previous sibling of element (or null if not found).

    However, in your shown markup, there is neither nor. There is only a DIV with a SPAN child having the marked class

    <div style="text-align: center"> <span class="marked">marked</span>
    

    If that is what you want to match, it’s the child combinator again. Of course, you have to change the b then to a div.

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

Sidebar

Related Questions

I am trying to use this in my page class. I only just started
I've just started to use linq to sql and have run into a problem
I've just started using Java's enums in my own projects (I have to use
I started trying to use sqlite to host small websites and on my own
I just started to use symfony 1.4 and Doctrine. (Used 1.0 - 1.2 +
So recently I've really started to use php actively, and I need some insights
I have just started learning GWT. My question is pretty simple: If I create
Just started learning to use the grid so please excuse me for the possibly
I just started learning how to use SwiftMailer and I am having trouble sending
I just started looking into jQuery yesterday, before this I programmed in only PHP.

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.