Reputation: 259
How to regex span tag exp.
<span id="n1">value here</span>
I need to get span id and "value here"?
Upvotes: 0
Views: 1507
Reputation: 4816
You shouldn't use regex to parse HTML. However, if you must, this should do it.
$regex = '#<span id="(.+?)">(.+?)</span>#';
preg_match($regex, $input, $groups);
$id = $groups[1];
$value = $groups[2];
This is in no ways absolutely bulletproof. Not by a long shot.
You should really take a look at something like DOMDocument
Upvotes: 1