Can anybody help me with preg_replace? I have an string where I need to filter this out:
health=0.30799794
"health=" Is there in the string every time. But the number behind is different. Is there a way to do it with perg_replace in PHP?
May be you are looking for this:
$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
Updates:
Just change the filter:
$filter = '/health=[0-9]*.[0-9]*/';
OR $filter = '/health=\\d*.\\d*/';
<?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.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.