Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/regex/17.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php preg_replace replacement属性中为空_Php_Regex_Null - Fatal编程技术网

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
表示替换为空字符串,即删除它。下次你可以在谷歌上做一个简单的搜索,找到相同的信息。

虽然尼古拉斯·马尔塔斯写的基本上是正确的,但有点不清楚

  • [^0-9\.]
    …将只匹配一个字符。-但是,True会替换所有匹配项,因为没有指定限制,因此会从字符串中删除所有其他字符
  • null
    表示替换为空字符串-看似正确,但手册中没有记录。经过多次搜索,我在字符串页面的以下部分找到了提示: 字符串转换是在 需要字符串的表达式
    NULL
    始终转换为空字符串


您可以在此处找到关于
preg\u replace
的解释: