How to get span tag content using preg_match function? [closed]
I have the following HTML code: <span role="button" class="a-n S1xjN" tabindex="0">414,817 people</span> How to use preg_match function to get the 414817 number? Amal Murali The Better Solution A regex is the wrong tool here. HTML is not a regular language , and cannot be accurately parsed using regular expressions. Use a DOM parser instead. Not only is it much easier, it's more accurate and reliable, and won't break when the format of the markup changes in the future. This is how you would get the contents inside a <span> tag using PHP's built-in DOMDocument class: $dom = new DOMDocument;