Echo/return在变量之前添加空格

jsq*_*lla 1 php mysql

我有一些代码,它从数据库中获取信息,然后创建一个图像的路径并返回它,我在另一个页面上用作img src.

这是功能:

function getMainImage ()
{
    $query = "SELECT * FROM pictures WHERE username = '$_SESSION[username]' AND main = 'y' LIMIT 1";
    include 'connect.php';
    $result = mysql_query($query) or die (mysql_error());
    mysql_close($dbhandle);
    $row = mysql_fetch_assoc($result);
    $path = "images/t_$row[username]_$row[number].$row[ext]";
    return $path;
}
<img src="<?php echo getMainImage(); ?>" width="40" height="40" />
Run Code Online (Sandbox Code Playgroud)

查看页面源时的输出是:

<img src=" images/t_image_3.jpg" width="40" height="40" />
Run Code Online (Sandbox Code Playgroud)

在"images /"之前,从功能中添加了额外的空间.我已经尝试修剪路径,甚至在调用它时修剪功能,但都没有工作.有任何想法吗?

AD7*_*six 6

包括

你看到的空白几乎肯定来自这条线:

include 'connect.php';
Run Code Online (Sandbox Code Playgroud)

检查文件中的内容connect.php,并在打开前删除任何空格<?php,如果有空格?>,只需将其删除即可.