Click here to Skip to main content
15,887,135 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I want to convert following string into json. Following has a link to image then delimiter ',' then a link then a delimiter ',' then has another delimiter ',' between title and subtitle then another delimiter '#'.
Posted

1 solution

PHP
2 down vote



$list = explode("#", $str);

$outputArray = array();

foreach ($list as $line)
{
    list($image, $link, $title, $subtitle) = explode(',', $line);

    $outputArray[] = array(
        'image' => $image,
        'link' => $link,
        'title' => $title,
        'subtitle' => $subtitle,
    );
}

echo json_encode($outputArray);
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900