mhdi
asked on
PHP - extracting values from HTML
Hi,
I have the following HTML block in a variable called $innerHTML.
I need to extract the following data out -
$name = "Link Text"
$link = "link.html"
$phone = "555 123 123"
$address = "1407 Mayfair St, City West"
What is the best way?
Ive attempted to use Xpath Queries but it doesnt seem efficient as it requires a foreach loop to go through the query result.
Any suggestions are much appreciated.
Thankyou
I have the following HTML block in a variable called $innerHTML.
<a class="name" href="link.html">Link Text</a>
<span class="phone">
555 123 123
</span>
<p class="address secondary">1407 Mayfair St, City West</p>
I need to extract the following data out -
$name = "Link Text"
$link = "link.html"
$phone = "555 123 123"
$address = "1407 Mayfair St, City West"
What is the best way?
Ive attempted to use Xpath Queries but it doesnt seem efficient as it requires a foreach loop to go through the query result.
Any suggestions are much appreciated.
Thankyou
ASKER
The reason I don't like using xpath queries is because it returns a list of matching nodes which I then need to go over with a foreach loop to extract the nodevalue. As my html block only has one occurance of each item it doesnt seem like a good way to do it.
Maybe I should have said easier rather than inefficient.
Maybe I should have said easier rather than inefficient.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Please post the code you've tried and I'll show you how to measure the elapsed time.