Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

preg_match from some html code

How would I write a php preg_match() in php to pick out the 250 value. I have a large string of html code that I want to pick the 250 out of and I can't seem to get the regular expression right.

This is the html pattern I want to match - note that I want to extract the integer where the 250 is:

<span class="price-ld">H$250</span>

I have been trying for hours to do this and I can't get it to work lol

like image 211
Amy Neville Avatar asked Dec 13 '25 12:12

Amy Neville


1 Answers

preg_match('/<span class="price-ld">H$(\d+)<\/span>/i', $your_html, $matches);
print "Its ".$matches[1]." USD";

The regex actually depends on your code. Where are you exactly searching for?

like image 77
Nils Avatar answered Dec 15 '25 01:12

Nils