Hi, I am creating a form which should have the following code: <input type='text' value='<? echo $var; ?>'> This form has to be created using a php program. The problem is that I cannot store this string above in a php variable. $p = "<input type='text' value='<? echo $var; ?>'>"; Anyone here knows a simple method of doing this? thank you
Assuming you have $var stored, then $p can be set how you want as follows: $p := '<input type="text" value="'.$var.'">'; Choice of quotes is reversible but important to avoid having to 'escape' characters. Hope this helps, if not post why and I'll take a closer look
I'm curious, and maybe I missed it somewhere along the way, but what are the drawbacks to escaping characters vs using different quotes like you have there?
No, I cannot do this. I don't have to write a value in the form code while creating it. Basically the script which creates the form is called only once. Then form code is written in a file. But the form is called over and over from another script"s". Each time the value of $var could be different based on what user selected in that script which he is using now. It is the PHP code which has to be written in that file embedded within the form code. The bigger problem is that this is not the only field which needs php code embedded. Thank you for the help.
ip076 - nodrawbacks to escaping, just I find it easier to avoid when I can... lots of slashes or repeated characters can become a nightmare to debug. Jeet - if I understand you correctly, how about this: echo '<input type="text" value="'.$var.'">';
Hi CCD, Thanks for the help but this is not what I need. I figured out a way of doing this and if it works, I will post here. I think it will work... Will let you know. Bye
function createInputField($value){ return "<input type='text' value='". addslashes($value) . "'>"; } PHP: Bobby