1

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?

1
  • 1
    Turn up your error reporting. You would have seen the issue immediately. error_reporting = E_ALL Commented Aug 2, 2017 at 9:27

1 Answer 1

4

you have a typo change $partsimages1 to $partimages1

$partsimg1 = json_decode($partimage1);
Sign up to request clarification or add additional context in comments.

1 Comment

Sometimes takes a fresh eye to notice such a stupid mistake.. Thanks!

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.