I want to get the value inside a span id or div id. For example from
<span id="lastPrice">29.00</span>
i want to get the 29.00. please help.
Asked
Active
Viewed 1,782 times
0

Alex Jose
- 444
- 1
- 6
- 17
-
2Use PHP DOM, not Regex. It's less likely to break horribly. – TRiG Aug 09 '11 at 14:33
-
http://stackoverflow.com/questions/1732348/regex-match-open-tags-except-xhtml-self-contained-tags/1732454#1732454 – singpolyma Aug 09 '11 at 14:45
-
possible duplicate of [Best methods to parse HTML with PHP](http://stackoverflow.com/questions/3577641/best-methods-to-parse-html-with-php) – Gordon Aug 09 '11 at 15:19
2 Answers
0
If you want to do this through regexp
that badly.
$string = "<span id=\"lastPrice\">29.00</span>";
preg_match("/\<span id\=\"lastPrice\"\>([\d.]+?)\<\/span\>/",$string,$match);
print "<pre>"; var_dump($match[1]); print "</pre>";
But there are far more better ways.

ace
- 7,293
- 3
- 23
- 28
0
Take a look at XPath => PHP - Searching and filtering with XPath
[...] XPath is a darn sight easier than regular expressions for basic usage. That said, it might take a little while to get your head around all the possibilities it opens up to you!
Google will give u plenty of examples and tutorials.

Milde
- 2,144
- 3
- 17
- 15