Reputation: 167
I'm trying to replace a string which contains value with operator : like "2456:72" to "2456.72" where data is fetched from mysql, I tried using str_replace
which sucks. $row_loop3["Tot_minutes"]
is the row which I should replace the character, please find my code:
$mysqli = new mysqli("172.16.10.102", "******", "RND@ISO-3306", "eTrans");
if (!$mysqli->multi_query("call sp_get_Android_Online_minutes_Chart ('2015-01-01','2016-01-30')")) {
$response["success"] = 0;
}
do {
if ($res_loop3 = $mysqli->store_result()) {
$response_loop3["minutes"] = array();
$find = ":";
$re = ".";
while ($row_loop3 = $res_loop3->fetch_assoc()) {
$j = 5;
$value_loop3 = array();
$value_loop3["File_Day"] = $row_loop3["edit_date"];
$value_loop3["File_Minutes"] = $row_loop3["FileDay"];
$val["Tot1_Minutes"] = $row_loop3["Tot_minutes"];
$value_loop3["Total_Minutes"] = str_replace($val, $find, $re); //value which I should replace : with .
array_push($response_loop3["minutes"], $value_loop3);
$response_loop3["success"] = 1;
}
echo $merger = json_encode(array_merge($response, $response_loop2, $response_loop3));
$res->free();
}
} while ($mysqli->more_results() && $mysqli->next_result());
please help me, thanks in advance
Upvotes: 0
Views: 96
Reputation: 74
str_replace
should be used in this way:
str_replace( mixed $search , mixed $replace , mixed $subject [, int &$count ] )
The function's argument are search, replace, and subject, so for your case should be like : str_replace($find,$re,$val)
Upvotes: 1
Reputation: 3124
You are not making variable instead you are making associative array. change this
$val["Tot1_Minutes"] = $row_loop3["Tot_minutes"];
to
$val= $row_loop3["Tot_minutes"];
and also order in str function to
$val = $row_loop3["Tot_minutes"];
$value_loop3["Total_Minutes"]=str_replace($find,$re,$val);
Upvotes: 1