I want to remove the last comma from below array.
{"location":"Park Town,Chennai,Tamil Nadu" },
{"location":"Arajar Salai,Simmakkal,Madurai" },
I want to remove the last comma from below array.
{"location":"Park Town,Chennai,Tamil Nadu" },
{"location":"Arajar Salai,Simmakkal,Madurai" },
Jon Stirling have right in his comment. If you try to create json manually - it's bad idea.
But anwser to your question should be something like this (didn't test it) :
<?php
$tab=explode(",",$string);
array_pop($tab);
$string=implode(",",$tab).']';
?>
Just use php rtrim() function on the string you will get your result.
like below
<?php
$text = '{"location":"Park Town,Chennai,Tamil Nadu" },{"location":"Arajar Salai,Simmakkal,Madurai" },';
$test = rtrim($text,',');
echo $test;
?>
A live example https://eval.in/849038