Insert image in json

0

Very good, I'm going through a json in php and it depends on the value of one of the fields, I would like to concatenate an image to the field, if I put a text works well but doing it in this way with an image does not. Any suggestions? Thanks

foreach ($obj as $data) 
    {  
        if ($data->estado_col == '1')
        {
        $data->name= <img src='bombillaV.png' > .($data->name); 
        }
    }  
    
asked by Lorenzo Martín 20.10.2017 в 19:26
source

1 answer

1

JSON DEFINITION

  

JSON , acronym for JavaScript Object Notation , is a format for   light text for the exchange of data.

As the definition says it is a text format so you can not add in the html tags, what you can do is simply add the name of the image and at the time you want print flames the property in which you kept that name and go.

This you could do to save:

foreach ($obj as $data) 
{  
    if ($data->estado_col == '1')
    {
    $data->imagen = 'bombillaV.png';
    }
} 

And this to print:

foreach ($obj as $data) 
    {  
        if ($data->estado_col == '1')
        {
        echo '<img src="imagenes/'. $data->imagen .'">'
        }
    }
    
answered by 20.10.2017 / 20:04
source