0

i have some json values coming from database, i want to split them so later i can use them where i want. Here is the json string.

$data = {"DATA-block-C5e35a3f127fb6":"01#ffff000images\/250place.jpg\u00b8"}

What i did was :

$decode = json_decode($data, true);
$datablock = $decode->DATA-block-C5e35a3f127fb6;
echo $datablock;

it returns the full value, but i want it like, #ffff000 seperate from images/250place.jpg, because #fff is the background color of that block and the other value is image. and also both things are not static. its a submission form. which has hidden values like these. is there a way i can grab them? Any help will appreciated.!

Ayaan
  • 9
  • 2
  • 1
    Please go through some of your existing questions and mark any [answered](https://meta.stackexchange.com/questions/5234/how-does-accepting-an-answer-work) where appropriate. – Nigel Ren Feb 02 '20 at 07:26
  • possible duplicate https://stackoverflow.com/questions/5941832/php-using-regex-to-get-substring-of-a-string – Serghei Leonenco Feb 02 '20 at 07:31

1 Answers1

0

As your first line decodes the JSON to an array (using json_decode() with true as the second parameter), you need to use array notation...

$datablock = $decode->DATA-block-C5e35a3f127fb6;

to

$datablock = $decode['DATA-block-C5e35a3f127fb6'];
Nigel Ren
  • 56,122
  • 11
  • 43
  • 55