current position:Home>How does PHP render some of the following JSON data into HTML

How does PHP render some of the following JSON data into HTML

2022-05-15 04:50:13CSDN Q & A

PHP How to request the following link to json stay HTML It's rendered in Chinese ?
https://pixabay.com/api/?key=20762951-7eebd38ed836f5a1103ccfe38&q=yellow+flowers&image_type=photo

For example, put json Medium userImageURL Fill in the picture with the value src in ,user Value filled in p In the label , Then traverse it out .

<div>    <ul class="imglb">        <li><img src="json userImageURL value " ><p>json user value </p></li>        <li><img src="json userImageURL value " ><p>json user value </p></li>        <li><img src="json userImageURL value " ><p>json user value </p></li>        <li><img src="json userImageURL value " ><p>json user value </p></li>        <li><img src="json userImageURL value " ><p>json user value </p></li>    </ul></div><style>.imglb{ width:100%;}.imglb li{ list-style:none; float: left; text-align: center; margin: 10px;}</style>



Take the answer :

file_get_contents Get web site content ( Need configuration php.ini Turn on openssl, If you don't make a mistake file_get_contents(): Unable to find the wrapper &quot;https&quot; - did you forget to enable it when you configured PHP, Get rid of extension=openssl notes ),json_decode After it is converted to an object, you can traverse it . If it cannot be modified php.inc, It can be used curl Instead of

img

<meta charset="utf-8"><?php$s=file_get_contents("https://pixabay.com/api/?key=20762951-7eebd38ed836f5a1103ccfe38&q=yellow+flowers&image_type=photo&pretty=true");$o=json_decode($s,true);?><div> <ul class="imglb"> <?php foreach($o['hits'] as $item){ echo "<li><img src=\"".$item['userImageURL']."\"><p>".$item['user']."</p></li>"; } ?> </ul></div><style>.imglb{ width:100%;}.imglb li{ list-style:none; float: left; text-align: center; margin: 10px;}</style>

img


copyright notice
author[CSDN Q & A],Please bring the original link to reprint, thank you.
https://en.qdmana.com/2022/131/202205041636083780.html

Random recommended