PHP | Only first word showing in textbox from assigned sentence

|
| By Webner

Problem: After the first space in the string no data appears in the input field.

There is an issue when a string contains words with spaces and we want to display the whole string in an input field but after the first space, no data is displayed in the input field.

Solution: This problem occurs when we don’t display the string in double quotes.

For example: The string is:

$var= ”this is the first string”;
<input type=”text” id=”input” value=’.$var.’>

In this case, input field shows only “this” and rest of the string is not displayed.

So to overcome this problem we have to use the variable in double quotes and the whole string is displayed as it is.

For example:

$var=”this is the first string”;
<input type=”text” id=”input” value=” ’.$var.’ ”>

This is the right way.

Leave a Reply

Your email address will not be published. Required fields are marked *