簡體   English   中英

剪線,在第一個空格字符處修剪

[英]String cut, trim at first space character

我正在嘗試從數據庫中選擇值,並將每個值放在單獨的文本輸入字段中 我的代碼正常工作,但是,當我嘗試在文本字段上顯示字符串時,該字符串會在其第一個空格字符處被剪切或修剪。 例如:

value #1: "my-picture.jpg"

value #2: "my name"

如果我將兩個值放在上面並將它們插入文本字段內,則輸出將如下所示:

value #1: my-picture.jpg
value #2: my

這是我正在處理的代碼:

<?php 
$counter = 0;
while ($newArray = mysqli_fetch_array($res, MYSQLI_ASSOC)) {
echo "
<input type='text' value=".$newArray['my_picture'].">
<input type='text' value=".$newArray['my_name'].">
";
?>

怎么了? 謝謝你的幫助。

您需要以HTML形式引用值:

echo '
<input type="text" value="'.$newArray['my_picture'].'">
<input type="text" value="'.$newArray['my_name'].'">
';

同樣出於良好的考慮,最好在變量的值上使用htmlentities()htmlspecialchars()來編碼特殊字符:

echo '<input type="text" value="' . htmlentities($newArray['my_picture']) . '">
      <input type="text" value="' . htmlentities($newArray['my_name']) . '">';

嘗試查看源。

<input type='text' value=the content of your variable>

自然,“變量的內容”需要用引號引起來。 所以; 更改為:

<?php 
$counter = 0;
while ($newArray = mysqli_fetch_array($res, MYSQLI_ASSOC)) {
    echo '<input type="text" value="' . $newArray['my_picture'] . '">';
    echo '<input type="text" value="' . $newArray['my_name'] . '">';
}
?>

您需要用引號將值引起來。 就像是

echo "
  <input type='text' value='".$newArray['my_picture']."'>
  <input type='text' value='".$newArray['my_name']."'>
";

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM