任何人都可以帮助我使用preg_replace吗?我有一个字符串,我需要过滤掉它:
health=0.30799794
“health =”每次都在字符串中。但背后的数字是不同的。 有没有办法在PHP中使用perg_replace?
答案 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.