自动放入PHP空间 if($result->num\u rows>0){ 而($row=$result->fetch_assoc()){ $name=$row['name']; $contents=$row['contents']; 数组\u push($allnotes,“,$name,”:“,”,$contents,“Delete”,$name,”); } }否则{ array_push($allnotes,“无可用票据!”); }

自动放入PHP空间 if($result->num\u rows>0){ 而($row=$result->fetch_assoc()){ $name=$row['name']; $contents=$row['contents']; 数组\u push($allnotes,“,$name,”:“,”,$contents,“Delete”,$name,”); } }否则{ array_push($allnotes,“无可用票据!”); },php,Php,我的问题是上面的代码(here->value='>,$name,“'>)正在添加空格,这反过来会破坏它,因为我的其他代码无法正确读取它,无法了解如何停止这些空格。谢谢您的做法与: if ($result->num_rows > 0) { while($row = $result->fetch_assoc()) { $name = $row['name']; $contents = $row['contents']; array_push($allnot

我的问题是上面的代码(here->value='>,$name,“'>)正在添加空格,这反过来会破坏它,因为我的其他代码无法正确读取它,无法了解如何停止这些空格。谢谢

您的做法与:

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!");
}
$allnotes[]=”;
$allnotes[]=$name;
$allnotes[]=“:”;
$allnotes[]=“”;
$allnotes[]=$contents;
$allnotes[]=“
删除”; $allnotes[]=$name; $allnotes[]=“”;
在我看来,你真正想要的是。。(注意点运算符)

$allnotes[]=“.$name.”:“.$contents.”
删除“$name.”;
此代码绝对不会添加空格。这些只是
array\u push()的一系列参数。
但我知道您实际上想要实现什么?在变量上使用
trim()
来消除空白。但正如@Rizier123所指出的,这段代码并没有添加任何空格。我猜您希望将这些字符串连接起来,而不是将它们作为单独的数组项推送到
$allnotes
。如果是这样的话,就用点代替逗号。谢谢你,这些点在Jakub Matczak上解决了这个问题
$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>";