gpt4 book ai didi

PHP 替换从 mysql 获取的字符串中的字符

转载 作者:行者123 更新时间:2023-11-29 07:23:52 24 4
gpt4 key购买 nike

我正在尝试用运算符替换包含值的字符串:例如“2456:72”到“2456.72”,其中数据是从mysql获取的,我尝试使用str_replace,这很糟糕。 $row_loop3["Tot_minutes"] 是我应该替换字符的行,请找到我的代码:

$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());

请帮助我,提前致谢

最佳答案

您没有创建变量,而是创建关联数组。改变这个

 $val["Tot1_Minutes"] = $row_loop3["Tot_minutes"];

 $val= $row_loop3["Tot_minutes"];

并且还在 str 函数中订购

$val = $row_loop3["Tot_minutes"];
$value_loop3["Total_Minutes"]=str_replace($find,$re,$val);

关于PHP 替换从 mysql 获取的字符串中的字符,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35171221/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com