Victor
Victor

Reputation: 125

How do I take a PHP variable and insert it into HTML when the variable's value has a space in it?

I am using the "value" attribute in my HTML5 code. I get only part of the text of the variable to display in an HTML text field. I get the portion that is to the left of the first space in the variable. I want the entire string including the spaces in the variable's string. I tried using double quotes when I assign the PHP variable its value, but that was no different.

Here is my code:

<?php
$var1 = 'this is a test';
?>

<html>
<body>

<form action="nextpage.php" method="post">

neatfield: <input type="text" name="pk" value=<?php echo $var1; ?>>

<input type="submit">
</form>

</body>
</html>

How do I put the content of $var1 in the "neatfield" text field in the web page? I get only the word "this," and I want the entire string to show up.

Upvotes: 2

Views: 110

Answers (1)

chirag satapara
chirag satapara

Reputation: 1937

you just forgot to put "" in value .

<input type="text" name="pk" value="<?php echo $var1; ?>">

Try now , it will give you the appropriate result.

Upvotes: 6

Related Questions