|
|
|
ตัด String ตัวที่อยู่ก่อนตัวสุดท้ายออกยังไงคะ จะตัด comma ทิ้ง |
|
|
|
|
|
|
|
ต้องการตัด String ตัวสุดท้ายที่เป็น comma (,) ก่อนปีกค่ะ ออกค่ะ
Code (PHP)
$data = "[";
while ($row_RecordsetValue = mysql_fetch_assoc($RecordsetValue)) {
$data .= '{"rank":"'.$row_RecordsetValue['rank'].'","values":"'.$row_RecordsetValue['values'].'"}';
$data .= ",";
}
$data .= "]";
echo $data;
[{"rank":"1","values":"4"},{"rank":"2","values":"7"},{"rank":"3","values":"27"},{"rank":"4","values":"283"},{"rank":"5","values":"319"},{"rank":"6","values":"1"},{"rank":"7","values":"0"},{"rank":"8","values":"1"},{"rank":"9","values":"0"},{"rank":"10","values":"2"},{"rank":"11","values":"15"},{"rank":"12","values":"15"},{"rank":"13","values":"0"},{"rank":"14","values":"18"},{"rank":"15","values":"1"},{"rank":"16","values":"0"},{"rank":"17","values":"169"},{"rank":"18","values":"0"},{"rank":"19","values":"1"},{"rank":"20","values":"5"},{"rank":"21","values":"2"},{"rank":"22","values":"1"},{"rank":"23","values":"3"},{"rank":"226","values":"0"},]
ต้องการตัด , ก่อน ] ออกค่ะ
Tag : PHP, MySQL
|
ประวัติการแก้ไข 2016-03-02 20:15:15 2016-03-02 20:15:42 2016-03-02 20:15:58
|
|
|
|
|
Date :
2016-03-02 19:57:54 |
By :
noona |
View :
2137 |
Reply :
2 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$new_text = rtrim($text, ',');
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ใช้ json_encode เถอะครับไม่ยุ่งยากดี
Code (PHP)
$data = array();
while ($row_RecordsetValue = mysql_fetch_assoc($RecordsetValue)) {
array_push($data, array(
'rank' => $row_RecordsetValue['rank'],
'values' => $row_RecordsetValue['values']
));
}
echo json_encode($data);
|
|
|
|
|
Date :
2016-03-02 22:01:10 |
By :
Krungsri |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Load balance : Server 04
|