PHP 从字符串中删除非货币字符


php strip non currency characters from string

我有这个字符串

From: £5.95 (per linear metre)

我只希望留下£5.95

我知道这是用preg_replace完成的,但是如何呢?

$string = "From: £5.95 (per linear metre)";
    echo preg_replace("", "", $string);
preg_replace('/[^0-9.£]/', '', $string);

这应该适合您:

<?php
    $str = "From: £5.95 (per linear metre)";
    preg_match_all("/From:'s(.*'d+)/", $str, $matches);
    echo $matches[1][0];
?>