Reputation:
I've ran into an interesting quirk with a PHP script I'm running. Whenever I set a PHP variable with multiple words, and set the value of an HTML input to that variable, the contents of the variable is cut off to just the first word. Why is this? Any workarounds?
To my understanding, the phrase "Sentence Typed In PHP" should appear in the first input, but it only shows the first word, "Sentence" - What am I missing??
PHP:
<?php
$title = 'Sentence Typed In PHP';
echo "This is the title variable: " .$title;
echo "<br><input name='title' id='title' type='text' autofocus='autofocus' required value=".$title.">";
echo "<br><input type='text' value='Sentence Typed in HTML'>";
?>
Output:
Upvotes: 0
Views: 376
Reputation: 11
Try this :
<?php
$title = 'Sentence Typed In PHP';
echo 'This is the title variable: ' .$title;
echo '<br><input name="title" id="title" type="text" autofocus="autofocus" required value="'.$title.'">';
echo '<br><input type="text" value="Sentence Typed in HTML">';
?>
Upvotes: 0
Reputation: 2995
You are missing a set of quotes:
echo "<br><input name='title' id='title' type='text' autofocus='autofocus' required value='".$title."'>";
Upvotes: 5