Reputation: 2659
I am trying to decode a json object so I can get an image url from it. Usually this works fine, but somehow the following code is not working for me.
$partimages1 = $prods['images'];
$partsimg1 = json_decode($partsimages1);
if($partsimg1->image_intro != ''){
$productimages = '<img class="kw-prodimage-img" src="cms/'.$partsimg1->image_intro.'" alt="Product 1" title="Product 1" />';
}else{
$productimages = '<img class="kw-prodimage-img" src="images/backgroundheader.jpg" alt="Product 1" title="Product 1" />';
}
The above code always returns backgroundheader.jpg while there is an image inside the object.
When I echo $partimages1 this is the result:
{"image_intro":"images\/Afbeeldingen\/lassen2.jpg","float_intro":"","image_intro_alt":"","image_intro_caption":"","image_fulltext":"","float_fulltext":"","image_fulltext_alt":"","image_fulltext_caption":""}
What is going wrong?
Upvotes: 1
Views: 345
Reputation: 6311
you have a typo change $partsimages1
to $partimages1
$partsimg1 = json_decode($partimage1);
Upvotes: 4