Assuming the HTML in your post is in a variable $str, this is fairly straightforward:
// Parse the HTML string into a DOM object
$html = str_get_html($str);
// Find the second nested span inside the <div class="adds-info">, then get its parent
$span = $html->find('.adds-info span span', 1)->parent;
// Get the innerhtml of the parent span
$name = $span->innertext;
If the number of elements changes, you need to check each one for the text you're looking for...
// Get all spans inside the <div class="adds-info">
$spans = $html->find('.adds-info span');
// Loop through each span, looking for "Your name:"
foreach ($spans as $span) {
if (strpos($span->innerhtml, "Your name:") !== FALSE) {
$name = $span->innerhtml;
}
}
:first-childare not supported. You can do something like$simpledomobject->find(".adds-info span span", 1), would that help? To print the text, you'd doecho $simpledomobject->find(".adds-info span span", 1)->innertext;