www.webdeveloper.com
Results 1 to 4 of 4

Thread: String to array conversion

  1. #1
    Join Date
    Jan 2005
    Location
    Alicante (Spain)
    Posts
    7,742

    String to array conversion

    Anyone see a simple way to convert this string into this array?

    Code:
    {"inStandby": "false", "currservice_begin": "13:15", "muted": false, "isRecording": "false", "currservice_station": "BBC 1 South", "currservice_serviceref": "1:0:1:2871:800:2:11A0000:0:0:0:", "volume": 25, "currservice_name": "Bargain Hunt", "currservice_end": "14:00", "currservice_description": ""}
    PHP Code:
    array (
      
    'inStandby' => 'false',
      
    'currservice_begin' => '13:15',
      
    'muted' => 'false',
      
    'isRecording' => 'false',
      
    'currservice_station' => 'BBC 1 South',
      
    'currservice_serviceref' => '1:0:1:2871:800:2:11A0000:0:0:0:',
      
    'volume' => '25',
      
    'currservice_name' => 'Bargain Hunt',
      
    'currservice_end' => '14:00',
      
    'currservice_description' => '',

    Can be a variable number of keys and no particular key is guaranteed to exist. The key is always in quotes, but the value may or may not be.

  2. #2
    Join Date
    Jul 2013
    Location
    Voorheesville NY USA
    Posts
    890
    exploade the string on the commas; loop thru that array and explode each entry on the : then take item 0 as the key of a new array with item 1 as the value.

  3. #3
    Join Date
    Aug 2004
    Location
    Ankh-Morpork
    Posts
    19,634
    Looks like JSON to me:
    PHP Code:
    $array json_decode($theStringtrue); 
    "Please give us a simple answer, so that we don't have to think, because if we think, we might find answers that don't fit the way we want the world to be."
    ~ Terry Pratchett in Nation

    eBookworm.us

  4. #4
    Join Date
    Jan 2005
    Location
    Alicante (Spain)
    Posts
    7,742
    Quote Originally Posted by NogDog View Post
    Looks like JSON
    Thanks Nogdog.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles