0
單個字母刪除一切如何修改這個代碼從一個給定的字符串中刪除一切exept號(已有)和串:「」 「k」,「B」和「M」?從一個字符串,但數字,點與了preg_replace
什麼Im做是解析中給出價格:123K,124.7B,20M
preg_replace("/\D/", "", "<td>Cost: 20b $, Sell for: 139k $</td>");
單個字母刪除一切如何修改這個代碼從一個給定的字符串中刪除一切exept號(已有)和串:「」 「k」,「B」和「M」?從一個字符串,但數字,點與了preg_replace
什麼Im做是解析中給出價格:123K,124.7B,20M
preg_replace("/\D/", "", "<td>Cost: 20b $, Sell for: 139k $</td>");
這應該做的伎倆(如有關定義):
preg_replace("/[^\.kBM0-9]/", "", "<td>Cost: 20b $, Sell for: 139k $</td>");
我認爲一個可能的preg_match更好,特別是如果你的字符串中有多個數字(如你的例子):
preg_match_all("/([0-9]+(\.[0-9]+)?\s?[kBM]?)/", "<td>Cost: 20b $, Sell for: 139k $</td>", $match);
所有的數字應該是n在$match
陣列中被很好地分開。