php_padawan Posted May 23, 2013 Share Posted May 23, 2013 I would like to request a little help from all of you. I would like to know how can I approach this in php. I have this string of data: {"a_stepActual":"99","a_StepReached":"99","a_ShowBack":"1","a_Similar":"","a_JMStarted":"1","a_GarmentStatus":"2","s_Step1":"1","s_Step2":"3","s_Step3":"7","s_Step4":"19","s_Step4_s":"2","s_Step5":"22","s_Step5_s":"2","s_Step6":"2816","s_Step7":"2819","s_Step8":"2821","s_Step8_s":"2","s_Step8_r":"3","s_Step9":"36","s_Step9_s":"0","s_Step9_r":"0","s_Step10":"2826","s_Step10_s":"2","s_Step10_r":"0","s_Step11":"2830","s_Step11_s":"2","s_Step11_z":"0","s_Step11_r":"3","s_Step12":"2836","s_Step12_s":"0","s_Step12_z":"0","s_Step12_r":"0","s_Step13":"44","s_Step13_s":"2","s_Step13_z":"1","s_Step13_b":"20","s_Step14":"47","s_Step14_s":"2"} and I needed it to be converted to the attached file or be converted to a more readable format. I tried looping to no success. Here is what I have done so far, by the way: <html> <head> <title>Test String</title> </head> <body> <?php $JMData = "{\"a_stepActual\":\"99\",\"a_StepReached\":\"99\",\"a_ShowBack\":\"1\",\"a_Similar\":\"\",\"a_JMStarted\":\"1\",\"a_GarmentStatus\":\"2\",\"s_Step1\":\"1\",\"s_Step2\":\"3\",\"s_Step3\":\"7\",\"s_Step4\":\"19\",\"s_Step4_s\":\"2\",\"s_Step5\":\"22\",\"s_Step5_s\":\"2\",\"s_Step6\":\"2816\",\"s_Step7\":\"2819\",\"s_Step8\":\"2821\",\"s_Step8_s\":\"2\",\"s_Step8_r\":\"3\",\"s_Step9\":\"36\",\"s_Step9_s\":\"0\",\"s_Step9_r\":\"0\",\"s_Step10\":\"2826\",\"s_Step10_s\":\"2\",\"s_Step10_r\":\"0\",\"s_Step11\":\"2830\",\"s_Step11_s\":\"2\",\"s_Step11_z\":\"0\",\"s_Step11_r\":\"3\",\"s_Step12\":\"2836\",\"s_Step12_s\":\"0\",\"s_Step12_z\":\"0\",\"s_Step12_r\":\"0\",\"s_Step13\":\"44\",\"s_Step13_s\":\"2\",\"s_Step13_z\":\"1\",\"s_Step13_b\":\"20\",\"s_Step14\":\"47\",\"s_Step14_s\":\"2\"}"; //$JMData = "s_Step1":"1","s_Step2":"3","s_Step3":"7","s_Step4":"19","s_Step4_s":"2","s_Step5":"22","s_Step5_s":"2","s_Step6":"2816","s_Step7":"2819","s_Step8":"2821","s_Step8_s":"2","s_Step8_r":"3","s_Step9":"36","s_Step9_s":"0","s_Step9_r":"0","s_Step10":"2826","s_Step10_s":"2","s_Step10_r":"0","s_Step11":"2830","s_Step11_s":"2","s_Step11_z":"0","s_Step11_r":"3","s_Step12":"2836","s_Step12_s":"0","s_Step12_z":"0","s_Step12_r":"0","s_Step13":"44","s_Step13_s":"2","s_Step13_z":"1","s_Step13_b":"20","s_Step14; $JMData1 = str_replace("\"","",$JMData); $JMData2 = strpos($JMData1, "s_Step1"); $JMData3 = substr($JMData1, strpos($JMData1, "s_Step1"), 500); //echo $JMData1; //echo $JMData2; echo $JMData3; ?> </body> </html> Link to comment https://forums.phpfreaks.com/topic/278307-arranging-one-string-data-to-two-columns/ Share on other sites More sharing options...
Jessica Posted May 23, 2013 Share Posted May 23, 2013 Start with unserialize Edit: or actually I think that's JSON? Try JSON_decode Link to comment https://forums.phpfreaks.com/topic/278307-arranging-one-string-data-to-two-columns/#findComment-1431742 Share on other sites More sharing options...
php_padawan Posted May 23, 2013 Author Share Posted May 23, 2013 Start with unserialize Edit: or actually I think that's JSON? Try JSON_decode thanks for the advice. using JSON is much simpler and cooler. many thanks! here is the final working code: <html> <head> <title>JMData Decode</title> </head> <body> <?php $JMData = "{\"a_stepActual\":\"99\",\"a_StepReached\":\"99\",\"a_ShowBack\":\"1\",\"a_Similar\":\"\",\"a_JMStarted\":\"1\",\"a_GarmentStatus\":\"2\",\"s_Step1\":\"1\",\"s_Step2\":\"3\",\"s_Step3\":\"7\",\"s_Step4\":\"19\",\"s_Step4_s\":\"2\",\"s_Step5\":\"22\",\"s_Step5_s\":\"2\",\"s_Step6\":\"2816\",\"s_Step7\":\"2819\",\"s_Step8\":\"2821\",\"s_Step8_s\":\"2\",\"s_Step8_r\":\"3\",\"s_Step9\":\"36\",\"s_Step9_s\":\"0\",\"s_Step9_r\":\"0\",\"s_Step10\":\"2826\",\"s_Step10_s\":\"2\",\"s_Step10_r\":\"0\",\"s_Step11\":\"2830\",\"s_Step11_s\":\"2\",\"s_Step11_z\":\"0\",\"s_Step11_r\":\"3\",\"s_Step12\":\"2836\",\"s_Step12_s\":\"0\",\"s_Step12_z\":\"0\",\"s_Step12_r\":\"0\",\"s_Step13\":\"44\",\"s_Step13_s\":\"2\",\"s_Step13_z\":\"1\",\"s_Step13_b\":\"20\",\"s_Step14\":\"47\",\"s_Step14_s\":\"2\"}"; $dec = (json_decode($JMData)); echo "<table border = 1>"; foreach ($dec as $key => $value) { echo "<tr><td>". $key."</td><td>". $value ."</td></tr>"; }; echo "<table/>"; ?> </body> </html> Link to comment https://forums.phpfreaks.com/topic/278307-arranging-one-string-data-to-two-columns/#findComment-1431750 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.