如何在php中使用preg_replace()?

时间:2016-05-27 06:37:05

标签: php

任何人都可以帮助我使用preg_replace吗?我有一个字符串,我需要过滤掉它:

health=0.30799794

“health =”每次都在字符串中。但背后的数字是不同的。 有没有办法在PHP中使用perg_replace?

2 个答案:

答案 0 :(得分:0)

可能你正在寻找这个:

$filter = '/health=0.30799794/';
$str = 'I am not here and my health=0.30799794';

echo $str = preg_replace ($filter, "", $str); //I am not here and my

<强>更新

只需更改过滤器:

$filter = '/health=[0-9]*.[0-9]*/'; 要么 $filter = '/health=\d*.\d*/';

答案 1 :(得分:0)

        <?php
            $pattern    = "#(health=[0-9\.]*)#";
            $sample     = "The Student has not got the best health-status - health=0.30799794 and he is not so happy with it.";
            $result     = preg_replace($pattern, "", $sample);

            var_dump($result);
            //DUMPS: The Student has not got the best health-status -  and he is not so happy with it.