Get text value with PHP simple HTML DOM parser -
how can text value <span>your name:<span>
php simple html dom parser without children command?
<div class="adds-info"> <span>price:<span>1000000000 </span></span> <span>txt1</span> <span>your name:<span>aaa</span></span> <span>phone:<span>02632402210</span></span> </div>
assuming html in post in variable $str
, straightforward:
// parse html string dom object $html = str_get_html($str); // find second nested span inside <div class="adds-info">, parent $span = $html->find('.adds-info span span', 1)->parent; // innerhtml of parent span $name = $span->innertext;
if number of elements changes, need check each 1 text you're looking for...
// spans inside <div class="adds-info"> $spans = $html->find('.adds-info span'); // loop through each span, looking "your name:" foreach ($spans $span) { if (strpos($span->innerhtml, "your name:") !== false) { $name = $span->innerhtml; } }
Comments
Post a Comment