Php preg_replace replacement属性中为空
我构建了一个谷歌货币转换器,但我不理解这部分代码Php preg_replace replacement属性中为空,php,regex,null,Php,Regex,Null,我构建了一个谷歌货币转换器,但我不理解这部分代码 $converted_amount = preg_replace("/[^0-9\.]/", null, $get[0]); 这个模式的作用是什么,在这里什么是null 完整代码: $amount = urlencode($_POST['amount']); $from_Currency = urlencode($_POST['from']); $to_Currency = urlencode($
$converted_amount = preg_replace("/[^0-9\.]/", null, $get[0]);
这个模式的作用是什么,在这里什么是null
完整代码:
$amount = urlencode($_POST['amount']);
$from_Currency = urlencode($_POST['from']);
$to_Currency = urlencode($_POST['to']);
$get = file_get_contents("https://www.google.com/finance/converter?a=$amount&from=$from_Currency&to=$to_Currency");
$get = explode("<span class=bld>",$get);
$get = explode("</span>",$get[1]);
print_r($get);
$converted_amount = preg_replace("/[^0-9\.]/", null, $get[0]);
$amount=urlencode($_POST['amount']);
$from_Currency=urlencode($_POST['from']);
$to_Currency=urlencode($_POST['to']);
$get=文件\u获取\u内容(“https://www.google.com/finance/converter?a=$amount&from=$from_Currency&to=$to_Currency”);
$get=爆炸(“,$get”);
$get=explode(“,$get[1]);
打印(获取);
$converted_amount=preg_replace(“/[^0-9\.]/”,null,$get[0]);
[^0-9\.]
表示除数字以外的任何字符0123456789
和
。这将只匹配一个字符null
表示替换为空字符串,即删除它。下次你可以在谷歌上做一个简单的搜索,找到相同的信息。虽然尼古拉斯·马尔塔斯写的基本上是正确的,但有点不清楚
…将只匹配一个字符。-但是,True会替换所有匹配项,因为没有指定限制,因此会从字符串中删除所有其他字符[^0-9\.]
表示替换为空字符串-看似正确,但手册中没有记录。经过多次搜索,我在字符串页面的以下部分找到了提示: 字符串转换是在 需要字符串的表达式null
始终转换为空字符串NULL
preg\u replace
的解释: