Skip to content Skip to sidebar Skip to footer

How To Put A Php Array Of Strings Into Html Input Fields

I am trying to take elements from a php array and echo the results to a webpage in a list of text input fields. My problem is that the elements within $list are strings and for som

Solution 1:

Instead of this:

$new_string .= "<li><inputtype='text'size=60value=" . $element . "></li>";

Do this:

$new_string .= '<li><inputtype="text"size=60value="' . $element . '"></li>';

When you need to use double qoutes in a string you should begin/end with single quotes that makes it much easier.

When you need to use single quote in a string you should begin/end with double quotes, that makes it easier for you.

When you need to use both you better use single quotes.

Also the thing with double quotes it will check if there is a variable inside the string. When you use single quote you must use ' . $variable . '

Also take a look at the manual for more information about strings in php

http://www.php.net/manual/en/language.types.string.php

Solution 2:

You need to quote the value data just like you did type:

$new_string .= "<li><inputtype='text'size=60value='" . $element . "'></li>";

Post a Comment for "How To Put A Php Array Of Strings Into Html Input Fields"