I have a long string and part of that string is this: <span itemprop="ratingValue">9.26</span>
. I want to get 9.26 as a string (using explode?). Thanks for any help. PS: it is html code saved as string.
Asked
Active
Viewed 54 times
-1

Jetamo
- 11
- 2
-
4You should use an HTML parser library, such as `DOMDocument`. – Barmar Mar 16 '17 at 15:49
-
use preg_match and regular expression – bxN5 Mar 16 '17 at 15:50
1 Answers
0
Using preg_match()
:
$input = 'verylongstring<withother>random</withother>
tags<span itemprop="ratingValue"><9.26</span>';
preg_match('~<span itemprop="ratingValue">(.*?)</span>~', $input, $output);
echo $output[1]; // 9.26

Tom Udding
- 2,264
- 3
- 20
- 30
-
*"a long string and part of that string is"*… this'll probably match a bit too much… – deceze Mar 16 '17 at 15:52
-