How to make this regex match </span>
This is the type of HTML string in which I will perform matches:
<span class="q1">+12 Spell Power and +10 Hit Rating</span>
I want to get +12 Spell Power and +10 Hit Ratingfrom the above HTML. This is the code I wrote:
preg_match('/<span class="q1">(.*)<\/span>/', $gem, $match);
But because of <\/span>it it eludes /in </span>, so it does not stop the match, so I get a lot more data than I want.
How can I escape /in </span>while retaining part of it?
Thank.
+3
3 answers
Do not use regex to parse HTML. Use an HTML parser. See Reliable, mature HTML parser for PHP .
+2