繁体   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