Reputation: 3755
<strong class="tb-rmb-num"><em class="tb-rmb">¥</em>39.00</strong>
I'm trying to retrieve the number only without the currency sign
My current code is
$ret = $html->find('strong[class=tb-rmb-num]');
echo $ret[0];
This will retrieve it with the sign ¥39.00 Advice please, Thank you.
Upvotes: 0
Views: 134
Reputation: 4373
In php:
$string = '¥39.00';
if(preg_match('/([\d\.]+)/', $string, $m)){
echo $m[1];
}
Which outputs:
39.00
Ok, I will break this down:
preg_match('/([\d\.]+)/', $string, $m)
preg_match is a php function that allows us to look for pattern matches in a given string using regular expressions.
The regular expression in this case is: /([\d.]+)/
The value of $string in this example was set to ¥39.00. You will want to replace $string in my example with your $ret[0] instead.
$m is a variable placeholder to store our group matches (explained above)
The whole thing was wrapped in an if statement so you can do something if the pattern match was found else do something else if it wasn't.
For further reference:
Upvotes: 3