PHP Simple HTML DOM Parser -


i started use php simple html dom parser.

now i'm trying extract elements surrounded <b>-tag inclduing </b> exsiting html document. works fine

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

how can achieve show elements surrounded <b>,</b>-tags followed <span class="marked">?

update: i've used firebug css path elements. looks this:

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

but won't work... ideas?

update:

to clarify question here sample tr of document starting table , 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 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> 

try following css selector

b > span.marked 

that return span though, have $e->parent() b element.

also see best methods parse html alternatives simplehtmldom


edit after update:

your browser modify dom. if @ markup, see there 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, question not match queries. asked how find

elements surrounded <b>,</b>-tags followed <span class="marked">

that can read either mean

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

or

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

for first use child combinator have shown earlier. second, use adjacent sibling combinator

b + span.marked 

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

however, in shown markup, there neither nor. there div span child having marked class

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

if want match, it's child combinator again. of course, have change b div.


Comments

Popular posts from this blog

java - SNMP4J General Variable Binding Error -

windows - Python Service Installation - "Could not find PythonClass entry" -

Determine if a XmlNode is empty or null in C#? -