0

I want to add this symbol [ ] to the column "Post_images"
with basis data sql server

Like this,

“post_images” : “ht tp://img*sample*com/gambar1*jpg”, “ht tp://img*sample*com/gambar2*jpg”

to

“post_images” : [“ht tp://img*sample*com/gambar1*jpg”, “ht tp://img*sample*com/gambar2*jpg”]
2
  • 4
    Could you provide a little bit more context to the process. Are you inserting this data into the database? Is this data already in the database? Are these variables, if so how are they stored? Commented Dec 8, 2015 at 6:46
  • @Dennis this data already in the database, i want to insert this symbol [ ] to data in colomn "post_images" Commented Dec 8, 2015 at 7:00

3 Answers 3

1

In json the [] indicates a set of items.

Assuming you have an array with both strings inside then calling json_encode(array) should add the [ ].

See also this tutorial for more detais.

http://www.tutorialspoint.com/json/json_php_example.htm

Please do not write json on your own. Use the php functions instead.

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

Comments

0

You have to place array for post_images it mean if you have $data which you json_encodeing you should add your post images as sub array not string. Example

 $data = array(
     'param1' => "data ...",
     'post_images' => array(
          “ht tp://img*sample*com/gambar1*jpg”,
          “ht tp://img*sample*com/gambar1*jpg”
      );
 );

echo json_encode($data); // will output what you where looking for

Comments

0

Do the the following: '["ht tp://imgsamplecom/gambar1*jpg", "ht tp://imgsamplecom/gambar2*jpg"]'

Example: http://sqlfiddle.com/#!9/971279/1

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.