eregi_replace
Posted: Mon Sep 26, 2005 5:00 am
hi, i have a simple eregi_coding as shown below.
this coding works fine when we pass certain string only, e.g. rm 1.2m and it'll convert it to rm1200000. But what if we want to perform that out of a longer string which contains other information ?
For example i have a string like "bla bla bla bla rm 1.2m bla bla bla" which i want to convert it to "bla bla bla rm1200000 bla bla bla"
thanks in advance for any reply.
Code: Select all
if(eregi("^(rm){1,1}(\ )?[0-9]+(\.)?[0-9]*[m|k]?$",$str)){
$temp = $str;
$tpower = 1;
$temp = str_replace("rm","",$temp);
$temp = str_replace(" ","",$temp);
if(substr($temp,strlen($temp)-1) == "k") $tpower = 1000;
if(substr($temp,strlen($temp)-1) == "m") $tpower = 1000000;
$temp = str_replace("m","",$temp);
$temp = str_replace("k","",$temp);
echo "<br> temp ".$temp;
echo "<br> tpower ".$tpower;
$temp = $temp * $tpower;
echo "<br> total ".$temp;
}For example i have a string like "bla bla bla bla rm 1.2m bla bla bla" which i want to convert it to "bla bla bla rm1200000 bla bla bla"
thanks in advance for any reply.