php - 是否可以从 JSON 文件中获取 URL 以显示来自 img src 的图像
问题描述
(注意:json 新手)我有一个 JSON 文件,其中包含图像 URL(https://pastebin.com/TavfuziF),代码如下:
<!DOCTYPE html>
<html>
<body>
<center>
<?php
$jdata = file_get_contents("cats-in-moviesnew.json");
//decode the retrieved json file into an array
$contents = json_decode($jdata, true);
echo
//create the table
"<table style border=3px solid black; ><tr><th>Producer</th><th>Director</th><th>Title</th><th>Year made</th><th>URL</th><th>Image</th><th>Poster URL</th></tr>";
//filling the table
foreach($contents as $record) {
echo
"<tr>
<td>" . $record["fields"]["produced_by"] . "</td>
<td>" . $record["fields"]["directed_by"] . "</td>
<td>" . $record["fields"]["title"] . "</td>
<td>" . $record["fields"]["year"] . "</td>
<td>" . $record["fields"]["url"] . "</td>
<td>" .
$record["fields"]["url_poster"]
. "</td>
<td>" . $record["fields"]["url_poster"] . "</td>
</tr>";
}
?>
</body>
</center>
</html>
并且我一直试图弄清楚是否有可能在该代码中执行类似 <img src="$record["fields"]["url_poster"]"> (当前间隙在表格填充位中)之类的操作或不。我已经尝试了几件对我没有用的事情,我看到过关于将东西转换为 base64 的事情,但在我的水平上这对我来说非常复杂,我现在不知道还能做什么。任何帮助将不胜感激。
解决方案
没关系,我发现只需要在 $record["fields"]["url_poster"] 之前添加 {},所以它看起来像:"<img src={$record["fields"]["url_poster"]}>"
推荐阅读
- html - 在不改变现有样式的情况下将搜索图标放在输入的前面
- java - 我有 mAdView.loadAd(adRequest); 错误
- python - Pandas TypeError:转换函数对按组进行最大计算的数据类型无效
- amazon-web-services - 跨账户 S3 存储桶访问
- python - 从文本文件中获取矩阵的行、列平均值
- angular - 如何在角度 4 中使用管道获取独特元素
- android - 如何以编程方式从 github 下载 apk?
- sql - T-SQL (SQL Server):提取唯一的数据集/组
- angular - 条件边框颜色
- php - 如何在 PHP 中按值获取所有键的数组?