[英]String cut, trim at first space character
i'm trying to select values from the database and place each and every one on a separate text input field . 我正在尝试从数据库中选择值,并将每个值放在单独的文本输入字段中 。 my code works properly, however, when i tried to display a string on a text field, the string is cut or trimmed on its very first space character.
我的代码正常工作,但是,当我尝试在文本字段上显示字符串时,该字符串会在其第一个空格字符处被剪切或修剪。 for example:
例如:
value #1: "my-picture.jpg"
value #2: "my name"
if i were to place the two values above and insert them inside a text field, the output would be like this: 如果我将两个值放在上面并将它们插入文本字段内,则输出将如下所示:
value #1: my-picture.jpg
value #2: my
this is the code i'm working on: 这是我正在处理的代码:
<?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'].">
";
?>
What is wrong? 怎么了? Thanks for any help.
谢谢你的帮助。
You need to quote your values in your HTML form: 您需要以HTML形式引用值:
echo '
<input type="text" value="'.$newArray['my_picture'].'">
<input type="text" value="'.$newArray['my_name'].'">
';
Also for good measure it would be a good idea to use htmlentities()
or htmlspecialchars()
on the values in your variables to encode special characters: 同样出于良好的考虑,最好在变量的值上使用
htmlentities()
或htmlspecialchars()
来编码特殊字符:
echo '<input type="text" value="' . htmlentities($newArray['my_picture']) . '">
<input type="text" value="' . htmlentities($newArray['my_name']) . '">';
Try viewing the source.. That says: 尝试查看源。
<input type='text' value=the content of your variable>
Where 'the content of your variable' needs to be surrounded by quotes, naturally. 自然,“变量的内容”需要用引号引起来。 So;
所以; change it into:
更改为:
<?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'] . '">';
}
?>
You need to surround your value with quotes. 您需要用引号将值引起来。 Something like
就像是
echo "
<input type='text' value='".$newArray['my_picture']."'>
<input type='text' value='".$newArray['my_name']."'>
";
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.