我有这个字符串
From: £5.95 (per linear metre)
我只想保留£5.95
。
我知道这是用preg_replace完成的但是怎么做?
$string = "From: £5.95 (per linear metre)";
echo preg_replace("", "", $string);
答案 0 :(得分:7)
preg_replace('/[^0-9.£]/', '', $string);
答案 1 :(得分:2)
这应该适合你:
<?php
$str = "From: £5.95 (per linear metre)";
preg_match_all("/From:\s(.*\d+)/", $str, $matches);
echo $matches[1][0];
?>