0

I have the following in my database which stores as JSON and are images that I want to then display but I'm not sure on how to do a string replace to get rid of the [ " , and spaces and just grab the random string.png

["4a21da2670ce6528b2cffebf6f42cb1b8ade3c13.png","4d9465c0694079296b24f6e3be7b226eaa9f94dd.png"]

Above is what I get from my DB so how would one string replace this.

I have tried:

<img src="/uploads/products/'. str_replace("[", "", $pieces[$i]).'" width="35">

But to no avail.

Thanks in advance.

1
  • You do not str_replace json, you json_decode it Commented Sep 9, 2014 at 8:50

1 Answer 1

2

Try

$json = '["4a21da2670ce6528b2cffebf6f42cb1b8ade3c13.png","4d9465c0694079296b24f6e3be7b226eaa9f94dd.png"]';
$array = json_decode($json);

foreach($array as $a) {
    echo '<img src="/uploads/products/'.$a.'" width="35">';
}

This will output

<img src="/uploads/products/4a21da2670ce6528b2cffebf6f42cb1b8ade3c13.png" width="35">
<img src="/uploads/products/4d9465c0694079296b24f6e3be7b226eaa9f94dd.png" width="35">

(See example)

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

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.