PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
I have an HTML form that i would like to preload with default values by setting variables rather than hard coding the form itself. I have not been able to figure out how to do this though. Here is my function:
You are using single quotes to wrap what you are echoing out. Anything in there is passed directly. You are wanting double quotes which will evaluate variables and things like \n \t, etc.
Furthermore simply changing the echo ' ... ' to echo " ... " will cause you all sorts of problems. I would stick with the single quotes and use concatenation. eg...
I have to admit , I am still confused. From reading the attached link, Twindev, why does for example " '. $variable . ' " get expanded but " $variable" not get evaluated. after all the latter is enclosed in double quotes and I would think should be expanded.
$variable = "This is a string."
echo $variable . " And some more.";
// prints This is a string. And some more.
echo "$variable And some more.";
// prints This is a string. And some more.
echo '$variable And some more.';
// prints $variable And some more.
$variable2 = 'This is a string with "quotation" marks.';
echo "$variable2 And some more.";
// prints This is a string with "quotation" marks. And some more.
echo '$variable2 And some more.';
// prints $variable2 And some more.
"value=$site" or value=$site ( from my original form ) get processed to value=dogs.com ( after all they are wrapped in double quotes ). But this is not what happens.