I know that I will have a lot of mistakes, but for a simple task I seem to be using regular expressions.
preg_match_all('~(<span>(.*?)</span>)~', $html, $matches);
$matches[0] will contain all span tags and their contents, $matches[1] contains only content.
For more complex things, you can take a look at PHP Simple HTML DOM Parser or similar:
// Create DOM from URL or file $html = str_get_html($html); // Find all images foreach($html->find('img') as $element) { echo $element->src . '<br>'; }
Etc.
source share