0

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

2
  • Is there any errors? Commented Feb 3, 2016 at 7:48
  • @Mr.Engineer No, am getting result as {"File_Day":"2015-01-02","File_Minutes":"2","Total_Minutes":"."}, where entire string is replaced by "." Commented Feb 3, 2016 at 7:50

2 Answers 2

1

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);
Sign up to request clarification or add additional context in comments.

Comments

1

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)

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.