I'm trying to get the text data from a child node of an element using PHP and DOM.
Here is the HTML data I'm having trouble parsing. I'm trying to obtain the email address.
<tr>
<th>Engineer:</th>
<td id="contact_person">Jack Smith <<a href='mailto:[email protected]'>[email protected]</a>>
<table class='transparent'>
<tr>
<td>Work Phone</td>
<td>(555) 555-5555</td>
</tr>
</table>
</td>
Here is my current code for processing that element:
$contact = $dom->getElementById("contact_person")->nodeValue;
This is the result I'm getting:
Jack Smith Work Phone(555) 555-5555
UPDATE: Removing < and > and replacing with a single hyphen between name and email address returns the following:
Jack Smith - [email protected] Phone(555) 555-5555
This is what I want to get:
[email protected]
I tried to get the developer to move the "id=contact_person" to the anchor that holds the email address. Things work fine when I do that in test, but it is not possible to do in our system.
I'm sure it's apparent, but I'm not really familar with DOM and looking for any guidance...
FINAL UPDATE: THE FIX:
$dom->getElementById("contact_person")->firstChild->nextSibling->nodeValue;
Jack Smith Work Phone(555) 555-5555and notJack Smith &[email protected]>Work Phone(555) 555-5555?<and>and replacing with a single hypen-did at least make the email address appear:<td id="customer_engineer">Jack Smith - <a href='mailto:[email protected]'>[email protected]</a>produces the result:Jack Smith - [email protected] Phone(555) 555-5555contact_personis synonymous withcustomer_engineer.