I need get multiple values from span tags using php, for example :
<div>
<span class='name'>name value</span>
<span class='city'>city name</span>
<span class='street'>street name</span>
<span class='phone'>+17240000000</span>
</div>
<div>
<span class='name'>name value 2</span>
<span class='city'>city name 2</span>
<span class='street'>street name 2</span>
<span class='phone'>+17240000000 2</span>
</div>
I have to get span values using span class, i try this code to get the value, and it’s working put for just 1 value such as “name” :
<?
$html = "<div>
<span class='name'>name value</span>
<span class='city'>city name</span>
<span class='street'>street name</span>
<span class='phone'>+17240000000</span>
</div>
<div>
<span class='name'>name value 2</span>
<span class='city'>city name 2</span>
<span class='street'>street name 2</span>
<span class='phone'>+17240000000 2</span>
</div>";
$dom = new DOMDocument();
@$dom->loadHTML($html);
$dom_xpath = new DOMXPath($dom);
$entries = $dom_xpath->evaluate("//span[@class='name']");
foreach ($entries as $entry) {
echo $entry->nodeValue."<br />";
}
?>
Is there anyone to help me to retouch the code so i can get all values
Thanks
Try changing
Base on the above format you may want to try this (assuming that the className will never change and always present)
You need to escape you values before inserting them into db (sql injection) and a more efficient want of doing bulk insert —
Read more at insert multiple rows via a php array into mysql and http://en.wikipedia.org/wiki/SQL_injection
OR
to