使用\ n和php和pdo时,源代码输出没有正确缩进

时间:2014-12-30 00:16:32

标签: php html pdo

如果我在没有\n的情况下正常输出行,那么在源代码的同一行输出的所有内容都不是很好看。

所以我想知道如果这里有解决问题的方法。

第一行正确缩进,但是后面的行被粘贴到左侧墙而没有缩进,代码示例如下所示。

源代码:

               <div><img u="image" src="images/Wooden_skull.jpg" /></div>
<div><img u="image" src="images/Lion.jpg" /></div>
<div><img u="image" src="images/cat.jpg" /></div>
<div><img u="image" src="images/Here_we_go.jpg" /></div>
<div><img u="image" src="images/ruined_building.jpg" /></div>
<div><img u="image" src="images/DSC_0184.JPG" /></div>
<div><img u="image" src="images/Dragon.jpg" /></div>
<div><img u="image" src="images/Punk_Tron.jpg" /></div>
<div><img u="image" src="images/Baby_viking.jpg" /></div>

PHP代码:

foreach($dbo->query($sql) as $row) {
    $sliderimages .= '<div><img u="image" src="images/'.$row['image'].'" /></div>' . "\n";
}

1 个答案:

答案 0 :(得分:0)

要在PHP的源代码中(但不在网页中)创建缩进,请使用\t

使用此:

foreach($dbo->query($sql) as $row) {
    $sliderimages .= '\t\t<div><img u = "image" src = "images/' . $row['image'] .'" /></div>' . "\n";
}

应产生以下输出:

               <div><img u = "image" src = "images/Wooden_skull.jpg" /></div>
               <div><img u = "image" src = "images/Lion.jpg" /></div>
               <div><img u = "image" src = "images/cat.jpg" /></div>
               <div><img u = "image" src = "images/Here_we_go.jpg" /></div>
               <div><img u = "image" src = "images/ruined_building.jpg" /></div>
               <div><img u = "image" src = "images/DSC_0184.JPG" /></div>
               <div><img u = "image" src = "images/Dragon.jpg" /></div>
               <div><img u = "image" src = "images/Punk_Tron.jpg" /></div>
               <div><img u = "image" src = "images/Baby_viking.jpg" /></div>