簡體   English   中英

如何使用逗號和大括號從字符串中刪除大括號

[英]How to remove curly braces from a sting with comma and curly braces

如何從給定的字符串中刪除花括號我已應用於所有匹配項以更改字符串。

我的輸出看起來像這樣

 {"Category":"TATA Wiron TW02","Quantity":"33 Kgs","Total Price":"4125"},{"Category":"Tata Wiron Aayush","Quantity":"33 Kgs","Total Price":"3630"}

然后我會改變這種類型

Category:TATA Wiron TW02,Quantity:33 Kgs,Total Price:4125},{Category:Tata Wiron Aayush,Quantity:33 Kgs,Total Price:3630

但在這里,我遇到的問題是Total Price:4125},{Category:Tata Wiron AayushTotal Price:4125},{Category:Tata Wiron Aayush ,這是我們制造的這兩項,但動態地添加了這么多物品,如何將其刪除

我的代碼是:

<?php
session_start();
$out = $_SESSION["output"];
echo $out;
$data = preg_replace("/\{[^}]+\}/", "", $out);
$msg = trim($out, '{},');
$msg2 =  trim($msg, '"');
$msg3= str_replace('"','',$msg2);
echo $msg3;
?>

如何從給定的字符串中刪除花括號我已應用於所有匹配項以更改字符串。

我的輸出看起來像這樣

 {"Category":"TATA Wiron TW02","Quantity":"33 Kgs","Total Price":"4125"},{"Category":"Tata Wiron Aayush","Quantity":"33 Kgs","Total Price":"3630"}

然后我會改變這種類型

Category:TATA Wiron TW02,Quantity:33 Kgs,Total Price:4125},{Category:Tata Wiron Aayush,Quantity:33 Kgs,Total Price:3630

但在這里,我遇到的問題是Total Price:4125},{Category:Tata Wiron AayushTotal Price:4125},{Category:Tata Wiron Aayush ,這是我們制造的這兩項,但動態地添加了這么多物品,如何將其刪除

我的代碼是:

<?php
session_start();
$out = $_SESSION["output"];
echo $out;
$data = preg_replace("/\{[^}]+\}/", "", $out);
$msg = trim($out, '{},');
$msg2 =  trim($msg, '"');
$msg3= str_replace('"','',$msg2);
echo $msg3;
?>

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM