如何匹配%字符旁邊的第一個數字?正則表達式與給定字符旁邊的第一個數字匹配
<?php
$string = 'Get 30% off when you spend over £100 on electronics';
if(strpos($string,'% off') !== false) {
$number = preg_replace("/[^0-9%]/", '', $string);
return $number;
}
這將返回30%,100
任何幫助將是巨大的在此先感謝。
你想匹配30什麼把戲?我看到你的IF聲明,如果它不等於false。 – alda1234 2014-12-02 20:21:05