我得到了以下代码:
if ($result->num_rows > 0) {
while($row = $result->fetch_assoc()) {
echo'<img src="'.$row['url'].'"/>';
}
}以下输出带有空格和其后的行分隔符的行URL。
src="upload/imgurl.JPG <-- (Here is a space and on the next line the ")
"当我手动输入URL时,这一切都很好。此外,数据库中的URL没有空格、断线等。
为什么PHP/MySQL在我的字符串之后加上这个空格和空格?如果不硬编码修剪之类的东西,我怎么能解决呢?
发布于 2015-08-25 13:52:53
在数据库中添加数据之前,最好使用trim()函数。现在还可以对输出数据进行trim()。这没什么大不了的
发布于 2015-08-25 13:55:39
从字符串的开始和结束处修剪条空白(或其他字符)。在此:
if ($result->num_rows > 0) {
while($row = $result->fetch_assoc()) {
$trimmed = trim($row['url']);
echo'<img src="'.$trimmed.'"/>';
}
}https://stackoverflow.com/questions/32205819
复制相似问题