0

i have json decoded data. which is already stored in database. Here is the data.!

{"sortlist":"block[]=D5e35a3db27fb4&block[]=K5e35a3f027fb5&block[]=C5e35a3f127fb6&block[]=F5e35a3fc27fb7&block[]=G5e35a40327fb9&block[]=H5e35a40c27fba","save_cont_flag":"0","DATA-block-D5e35a3db27fb4":"0#TRANSP <p style=\"text-align: center;\" data-mce-style=\"text-align: center;\"><span style=\"background-color: rgb(241, 196, 15); color: rgb(224, 62, 45);\" data-mce-style=\"background-color: #f1c40f; color: #e03e2d;\">This is some text<\/span><\/p>","DATA-block-K5e35a3f027fb5":"0#TRANSP20","DATA-block-C5e35a3f127fb6":"01#ffff000images\/250place.jpg\u00b8","DATA-block-F5e35a3fc27fb7":"121212undefined","DATA-block-G5e35a40327fb9":"01#TRANSP#TRANSP","DATA-block-H5e35a40c27fba":"01#TRANSP#64cc34#4aa121270#ffffff#ffffff040930001000000000000Open Sans:800\u00b8\u00b8CHECK THIS OUT NOW - CLICK HERE\u00b8","page_name":"Page ba","aff_link":"","pause_link":"","seo_title":"","fbook":"","seo_desc":"","seo_keywords":"","back_color":"#EEEEEE","body_color":"#FFFFFF","back_image":"","ty_font_color":"#000000","ty_override":"","ty_name":"1234","ty_stm":"","modal_para_width":"0","catcha_url":"","catcha_un":"Yes","catcha_message":"","code_head":"","code_body":"","modal_share_width":"0","modal_cta_width":"0","modal_video_width":"0","modal_mp_width":"0","modal_stm_width":"0","modal_image_width":"0","modal_bonus_width":"1","ty_headline":"","modal_spacer_width":"0","att_bar_status":"0","att_delay_in":"0","att_bar_color":"#bbbbbb","att_gradient":"0","att_text_color":"#000000","att_text_font":"Open Sans:400","att_text_size":"14","att_bar_message":"Add Your Attention Bar Text Here","att_link_color":"#000000","att_link_label":"Add Link Text Here","att_link_url":"http:\/\/commissiongorilla.com","count_font":"Open Sans:800","count_size":"55","count_status":"1","count_type":"0","count_end":"02\/01\/2020 9:14 PM","count_zone":"0.0","count_eg_days":"0","count_eg_hours":"0","count_eg_mins":"0","count_digit_color":"#bbbbbb","count_label_color":"#bbbbbb","count_background":"0","count_language":"1","count_exp":"1","count_url":"http:\/\/commissiongorilla.com","count_add_days":"0","count_add_hours":"0","count_add_mins":"0","modal_countdown_width":"0","modal_review_width":"0"}

all i want todo is sort the first object "sortlist" i have tried to make it in array but it wont help. i want to manage it like:

D5e35a3db27fb4
K5e35a3f027fb5
C5e35a3f127fb6
F5e35a3fc27fb7
G5e35a40327fb9

How can i do this? Help is deeply appericiated.!

2
  • $sortList = json_decode($sortListJson); print_r(explode("block[]", $sortList->sortlist)); Commented Feb 2, 2020 at 6:16
  • @Ayaan check my answer, if its solved kindly accept it. Commented Feb 2, 2020 at 6:19

2 Answers 2

1

You can sort json like below,

$jsonobj = '{"sortlist":"block[]=D5e35a3db27fb4&block[]=K5e35a3f027fb5&block[]=C5e35a3f127fb6&block[]=F5e35a3fc27fb7&block[]=G5e35a40327fb9&block[]=H5e35a40c27fba","save_cont_flag":"0","DATA-block-D5e35a3db27fb4":"0#TRANSP <p style=\"text-align: center;\" data-mce-style=\"text-align: center;\"><span style=\"background-color: rgb(241, 196, 15); color: rgb(224, 62, 45);\" data-mce-style=\"background-color: #f1c40f; color: #e03e2d;\">This is some text<\/span><\/p>","DATA-block-K5e35a3f027fb5":"0#TRANSP20","DATA-block-C5e35a3f127fb6":"01#ffff000images\/250place.jpg\u00b8","DATA-block-F5e35a3fc27fb7":"121212undefined","DATA-block-G5e35a40327fb9":"01#TRANSP#TRANSP","DATA-block-H5e35a40c27fba":"01#TRANSP#64cc34#4aa121270#ffffff#ffffff040930001000000000000Open Sans:800\u00b8\u00b8CHECK THIS OUT NOW - CLICK HERE\u00b8","page_name":"Page ba","aff_link":"","pause_link":"","seo_title":"","fbook":"","seo_desc":"","seo_keywords":"","back_color":"#EEEEEE","body_color":"#FFFFFF","back_image":"","ty_font_color":"#000000","ty_override":"","ty_name":"1234","ty_stm":"","modal_para_width":"0","catcha_url":"","catcha_un":"Yes","catcha_message":"","code_head":"","code_body":"","modal_share_width":"0","modal_cta_width":"0","modal_video_width":"0","modal_mp_width":"0","modal_stm_width":"0","modal_image_width":"0","modal_bonus_width":"1","ty_headline":"","modal_spacer_width":"0","att_bar_status":"0","att_delay_in":"0","att_bar_color":"#bbbbbb","att_gradient":"0","att_text_color":"#000000","att_text_font":"Open Sans:400","att_text_size":"14","att_bar_message":"Add Your Attention Bar Text Here","att_link_color":"#000000","att_link_label":"Add Link Text Here","att_link_url":"http:\/\/commissiongorilla.com","count_font":"Open Sans:800","count_size":"55","count_status":"1","count_type":"0","count_end":"02\/01\/2020 9:14 PM","count_zone":"0.0","count_eg_days":"0","count_eg_hours":"0","count_eg_mins":"0","count_digit_color":"#bbbbbb","count_label_color":"#bbbbbb","count_background":"0","count_language":"1","count_exp":"1","count_url":"http:\/\/commissiongorilla.com","count_add_days":"0","count_add_hours":"0","count_add_mins":"0","modal_countdown_width":"0","modal_review_width":"0"}';


$jsonarr = json_decode($jsonobj);

$sortlist = $jsonarr->sortlist;

$sortlist_exp = explode('&',$sortlist);

foreach($sortlist_exp as $item){
    $temp = explode('block[]=',$item);
    $finalArr[]= $temp[1];
}

var_dump($finalArr);

You can also do the foreach like below,

foreach($sortlist_exp as $item){
    $finalArr[] = str_replace("block[]=","",$item); 
}

EDIT: As @Ayaan required the $finalArr in a single string, so he added like this

$final = implode("<br>", $finalArr); 
echo $final;

Thanks

Sign up to request clarification or add additional context in comments.

3 Comments

edit : I have used implode function at the end. to make it like i asked in the question."$final = implode("<br>", $finalArr); echo $final;"
@Ayaan you need the final in single string not in array?
Yes, in strings, so i can later equal them to data-blocks and then echo the value of data blocks.
0

First you should json decode it, then use explode function to convert this text in sortlist to array, this is the solution to have array:

$object = json_decode($data); $sortlist_array = explode("block[]=", $object['sortlist']);

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.