尝试回显外部URL中的图像时出现php错误

时间:2017-07-17 17:26:49

标签: php html url

Image With Explanation

在这张图片中,它解释得更好一点,但基本上在html栏中,我需要让用户名下的外部URL放置玩家头像。但我似乎无法让它工作我想我会在这里问,因为这个社区很有帮助这里是代码:

<?php
$connection = mysql_connect('REMOVED', 'REMOVED', 'REMOVED'); 
mysql_select_db('stats');

$query = "SELECT * FROM stats"; 
$result = mysql_query($query);

while($row = mysql_fetch_array($result)){   
echo "<tr><td><img src="'. "https://crafatar.com/avatars/" . $row['uuid'] .
 '">" . $row['name'] . "</td>";  
 echo "<td>" . $row['PLAYER_KILLS'] . "</td>";  
 echo "<td>" . $row['MOB_KILLS'] . "</td>";  
 echo "<td>" . $row['DEATHS'] . "</td>";  
 echo "<td>" . $row['DAMAGE_DEALT'] . "</td>";  
 echo "<td>" . $row['DAMAGE_TAKEN'] . "</td>";  
}



mysql_close(); 
?>

2 个答案:

答案 0 :(得分:2)

PHP会在括号中插入变量,因此您可以转义src标记中的引号,然后将变量括在{}中:

echo "<tr><td><img src=\"https://crafatar.com/avatars/{$row['uuid']}\">{$row['name']}</td>";

不需要连接,代码更清晰。这是一个EXAMPLE

结果是:

<tr><td><img src="https://crafatar.com/avatars/42">foo</td>

警告

您应该在PHP 7中删除stop using mysql_* functions These extensions。了解prepared PDO语句}和MySQLi并考虑使用PDO,it's really pretty easy

答案 1 :(得分:0)

这应该有效:

echo "<tr><td><img src=\"https://crafatar.com/avatars/\"" . $row['uuid'] . ">" . $row['name'] . "</td>"; 

使用\"转义"