0
我試圖讓這個圖像顯示從一個API調用在PHP中,在HTML中的IMG標記。顯示Api圖像
到目前爲止,這是我嘗試過,
<div class="col-md-3 col-lg-3 " align="center"><img alt="User Pic" <?php echo 'src="'. $data['response']['avatar'] . '"'; ?>
但它僅顯示用戶PIC,是不是因爲API是不是PHP裏面?下面的完整代碼。
<section class="section blog-detail">
<div class="container">
<div class="row">
<div class="col-md-5 toppad pull-right col-md-offset-3 ">
<br>
</div>
<div class="col-xs-12 col-sm-12 col-md-6 col-lg-6 col-xs-offset-0 col-sm-offset-0 col-md-offset-3 col-lg-offset-3 toppad" >
<div class="panel panel-info">
<div class="panel-heading">
<h3 class="panel-title">Profile</h3>
</div>
<div class="panel-body">
<div class="row">
<div class="col-md-3 col-lg-3 " align="center"> <img alt="User Pic" <?php echo 'src="'. $data['response']['avatar'] . '"'; ?> class="img-circle img-responsive"> </div>
<div class=" col-md-9 col-lg-9 ">
<table class="table table-user-information">
<tbody>
<?php
/* Check if button was clicked */
if (isset($_POST['someName'])) {
/* If id is empty or not a number, then don't proceed fetching data */
if (empty($_POST['id']) || !is_numeric($_POST['id'])) {
echo 'Invalid id';
} else {
/* Fetch data */
$data = file_get_contents('https://api.truckersmp.com/v2/player/' . $id = trim($_POST["id"]));
/* Decode json */
$data = json_decode($data, true);
/* Display id and name */
if (isset($data['response'])) {
/* You should add some checks to check if id and name actually exists and are not empty */
echo '
<tr><td>ID:</td><td><strong /> ' . $data['response']['id'] . '</td></tr>
<tr><td>Name:</td><td><strong /> ' . $data['response']['name'] . '</td></tr>
<tr><td>Join Date:</td><td><strong /> ' . $data['response']['joinDate'] . '</td></tr>
<tr><td>Steam 64:</td><td><strong /> ' . $data['response']['steamID64'] . '</td></tr>
<img src="'. $data['response']['avatar'] . '"></td></tr>
<tr><td>Group:</td><td><strong />' . $data['response']['groupName'].'</td></tr>';
}
}
}
?>
</tbody>
</table>
<a href="#" class="btn btn-primary">My Sales Performance</a>
<a href="#" class="btn btn-primary">Team Sales Performance</a>
</div>
</div>
</div>
<div class="panel-footer">
<a data-original-title="Broadcast Message" data-toggle="tooltip" type="button" class="btn btn-sm btn-primary"><i class="glyphicon glyphicon-envelope"></i></a>
<span class="pull-right">
<a data-original-title="Remove this user" data-toggle="tooltip" type="button" class="btn btn-sm btn-danger"><i class="glyphicon glyphicon-remove"></i></a>
</span>
</div>
</div>
</div>
</div>
</div>
</tbody>
</table>
</div>
</div>
</div>
</div>
</div>
</div>
</div>