fife Posted March 12, 2012 Share Posted March 12, 2012 Hi all. I have this code. <?php $ext = ' <form action="/members/clubs/view-activity.php" method="post" name="venuefrm"> <button type="submit" id="close" class="link"><span>View Activity</span></button> <input name="activity" type="hidden" value="<?php echo $activites['activityID']; ?>" /> </form>'; ?> The code falls down at the value="<?php echo $activites['activityID']; ?>" part. Can someone please show me how I break into php to write this part properly as I dont understand an it is obviously wrong. Thanks Danny Quote Link to comment https://forums.phpfreaks.com/topic/258732-echo-php-in-a-variable-with-html/ Share on other sites More sharing options...
AyKay47 Posted March 12, 2012 Share Posted March 12, 2012 You are already inside php tags, you don't need them again.' You need to concatenate the array value since the single index quotes will break the string. $ext = ' <form action="/members/clubs/view-activity.php" method="post" name="venuefrm"> <button type="submit" id="close" class="link"><span>View Activity</span></button> <input name="activity" type="hidden" value="' . $activites['activityID'] . '" /> </form>'; Quote Link to comment https://forums.phpfreaks.com/topic/258732-echo-php-in-a-variable-with-html/#findComment-1326379 Share on other sites More sharing options...
Muddy_Funster Posted March 12, 2012 Share Posted March 12, 2012 The other way to do it is to change your quotes. PHP takes single quotes as literal, as in it will build a sting with exactly what is inside them, without preprocessing the values of any variables that you put in in, use double quotes to get around this. In your example you have a lot of double quotes inside the string, so you would either need to change them all to single quotes or escape them by putting a \ directly before them. also, when using array values in a double quoted sting wrap the declaration inside {}. so using the escaped method it would look like this: <?php $ext = " <form action=\"/members/clubs/view-activity.php\" method=\"post\" name=\"venuefrm\"> <button type=\"submit\" id=\"close\" class=\"link\"><span>View Activity</span></button> <input name=\"activity\" type=\"hidden\" value=\"{$activites['activityID']}\" /> </form>"; ?> Another way to write blocks of string content into a variable is to use <<<UID to open the block and UID; to close it, where UID is a unique name for the string block. eg: <?php $ext = <<<FORM <form action="/members/clubs/view-activity.php" method="post" name="venuefrm"> <button type="submit" id="close" class="link"><span>View Activity</span></button> <input name="activity" type="hidden" value="{$activites['activityID']}" /> </form>; FORM; ?> You must make sure that there are no leading spaces on the line where you close the block (FORM; in this case) or it will create an error. Quote Link to comment https://forums.phpfreaks.com/topic/258732-echo-php-in-a-variable-with-html/#findComment-1326385 Share on other sites More sharing options...
fife Posted March 12, 2012 Author Share Posted March 12, 2012 Guys thank you very much for your help and both your solutions work nicely. Quote Link to comment https://forums.phpfreaks.com/topic/258732-echo-php-in-a-variable-with-html/#findComment-1326386 Share on other sites More sharing options...
Muddy_Funster Posted March 12, 2012 Share Posted March 12, 2012 no problem, glad to help. Quote Link to comment https://forums.phpfreaks.com/topic/258732-echo-php-in-a-variable-with-html/#findComment-1326388 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.