Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
541 views
in Technique[技术] by (71.8m points)

php - Only first word of string appearing in HTML form when using string-reference

I'm having a problem with a HTML form and php.

I'm trying to make the default-value of a form-text field to be a pre-defined string. For this I'm using a reference. However, whenever I try to place a string into the form using PHP or references in any kind shape or form, only the first word gets added.

Here is a picture to describe the situation:

enter image description here

Does anyone know why this is happening, and/or a way to work around this issue?

Actual code:

<?php 
    Echo "<input type="text" name="Address" value="one two three"><br>";
?>

<?php 
    $str ="one two three";
    Echo "<input type="text" name="Address" value=" . $str . "><br>";
?>

<input type="text" name="Address" value=<?php echo "one two three";?>><br>
<input type="text" name="Address" value=<?php $str = "one two three"; echo $str;?>><br>
<input type="text" name="Address" value="one two three"><br>
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

You don't quote the echoed words. Basically you do this:

<input type="text" value=one two three />

But you need to do that:

<input type="text" value="one two three" />

Just add "" around the PHP.

BTW: You need to escape these if you don't want to get XSSed. These attacks are quite scary. Read about it here: https://www.owasp.org/index.php/Cross-site_Scripting_(XSS)


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...