PHP空间自动放入

时间:2017-02-28 17:53:48

标签: php

if ($result->num_rows > 0) {

while($row = $result->fetch_assoc()) {
    $name = $row['name'];
    $contents = $row['contents'];
    array_push($allnotes,"<b>",$name,":","</b>",$contents,"<br>   <form action='notes/delete-note.php' method='post'> <input type='hidden' name='removenote' value='",$name,"'> <button type='submit'        class='notedelete'>Delete ",$name,"</button> </form>");
 }
} else {
array_push($allnotes,"No avaliable notes!");
}

我遇到的问题是上面的代码(这里 - &gt; value ='“,$ name,”'&gt;)正在添加空格,这反过来打破了它,因为我的其他代码无法正确阅读它阻止这些空间。感谢

1 个答案:

答案 0 :(得分:0)

你的方式与:

相同
$allnotes[] = "<b>";
$allnotes[] = $name;
$allnotes[] = ":"; 
$allnotes[] = "</b>";
$allnotes[] = $contents; 
$allnotes[] = "<br>   <form action='notes/delete-note.php' method='post'> <input type='hidden' name='removenote' value='"; 
$allnotes[] = $name; 
$allnotes[] = "'> <button type='submit'        class='notedelete'>Delete "; 
$allnotes[] = $name; 
$allnotes[] = "</button> </form>";

在我看来,你真正想要的是......(注意点运算符)

$allnotes[] = "<b>".$name.":"."</b>".$contents."<br>   <form action='notes/delete-note.php' method='post'> <input type='hidden' name='removenote' value='".$name."'> <button type='submit'        class='notedelete'>Delete ".$name."</button> </form>";