Double quotes and HTML

From: Date: Thu, 17 Nov 2005 06:59:07 +0000
Subject: Double quotes and HTML
Groups: php.windows 
Request: Send a blank email to php-windows+get-26501@lists.php.net to get a copy of this message
Hi all, I'm rather new to PHP... Am taking a maximal PHP, minimal HTML approach; came from a C/Java background. I'm use a staged (e.g. stage1, stage2) forms page for the creation of new user accounts, so I'm getting variables out of $_POST if there are any. Problem is... I'm getting a weird parse error: Parse error: parse error, expecting T_STRING' or T_VARIABLE' or `T_NUM_STRING' in ... My code is as follows: 1 if (isset($_POST["user_id"])) 2 echo "<br><input type='text' name='user_id' size='40' maxlength='15' value='$_POST[\"user_id\"]'>"; 3 else 4 echo "<br><input type='text' name='user_id' size='40' maxlength='15'>"; I know it has something to do with line 2, because HTML does not support the use of slashes to escape double quotes. I guess the solution would be to simply declare an additional variable and refer to it in the if..else part. 1 $user_id = $_POST["user_id"]; 2 3 if (isset($_POST["user_id"])) 4 echo "<br><input type='text' name='user_id' size='40' maxlength='15' value='$user_id'>"; 5 else 6 echo "<br><input type='text' name='user_id' size='40' maxlength='15'>"; But it just seems so... Inelegant. Is there anyway I can just refer to $_POST variables directly, instead of having to declare a new variable? Thanks a lot! =)

« previous php.windows (#26501) next »