Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

getting value using xpath and dom in php

Tags:

html

dom

php

xpath

this the part of the html i want to parse:

<center>
<table border="0" cellpadding="0" cellspacing="0"  >
<td>
Some text
<br>
<font color=brown>label0</font>Value0
<br>
<font color=brown>Label1</font>Value1.<br>
Some text
<br>

<font color=brown>Label2</font>Value2<br>
</td>
</table>

</center>

I want to get Value0 and Value1.

If i use this:

$index=$element->nodeValue;

where element is the query to the .../font I get the Label0,1,2. But I want the Value. How to do it? I can also give more code if it is necessary.

like image 598
ghostrider Avatar asked Mar 10 '26 23:03

ghostrider


2 Answers

Try perhaps:

$index=$element->nextSibling->nodeValue;

To get the value of the node after the font node.

like image 111
yiding Avatar answered Mar 13 '26 14:03

yiding


<center>
<table border="0" cellpadding="0" cellspacing="0"  >
<td>
Some text
<br>
<font color=brown>label0</font><span>Value0</span>
<br>
<font color=brown>Label1</font><span>Value1.</span><br>
Some text
<br>

<font color=brown>Label2</font>Value2<br>
</td>
</table>
</center>

try putting span just as above and instead of quering font query for span... hope it will help..

like image 43
Nipun Jain Avatar answered Mar 13 '26 14:03

Nipun Jain



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!