PHP question
Community Forums/General Help/PHP question
| ||
Hi all, here's a quick PHP question, I am new to PHP so still learning but there's one issue I realy need to find a solution for. I want to name a form button using a variable specified at the start of the document, it works but will only show the first word, seems like once it hits a space it stops. In the code below the text displayed on the button will be 'button' instead of 'button name with spaces'. Hope thats clear. <?php $buttonname = "button name with spaces"; ?> <!-- lots of HTML stuff here --> <form method="get" action="engine.php"> <input name="Issue" type="submit" id="Issue03" value=<?php echo $buttonname; ?> /> </form> |
| ||
I think there's some problem in HTML code with quote and double quotes.<?php $buttonname = "button name with spaces"; ?> <!-- lots of HTML stuff here --> <form method="get" action="engine.php"> <input name="Issue" type="submit" id="Issue03" value='<?php echo $buttonname; ?>' /> </form> |
| ||
Basically this code <input name="Issue" type="submit" id="Issue03" value=<?php echo $buttonname; ?> /> should be <input name="Issue" type="submit" id="Issue03" value="<?php echo $buttonname; ?>" /> with quotes around the <?php echo $buttonname; ?>. Otherwise the HTML parser uses the first space in the string as a delimiter for the HTML attribute value. The double quotes that appear in the $buttonname = "button name with spaces"; code don't actually form part of the string, but instead act as delimiters. |
| ||
Thanks guys, makes sense now that you explain. =D |