Re: embedding php inside of php
| From: | Tim Streater | Date: | Sun, 01 Jul 2012 12:01:00 +0000 |
| Subject: | Re: embedding php inside of php | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-318356@lists.php.net to get a copy of this message | ||
On 01 Jul 2012 at 01:00, Tim Dunphy <bluethundr@gmail.com> wrote:
> I am trying to get the hang of php using some examples that I found
> in a book. I've been making progress lately, but one thing has me a
> bit stumped.
>
> In an HTML form that I am echoing through PHP I would like to embed
> smaller chunks of php in the code like so:
>
>
> echo '<br /><br />
> <form method="post" action="sendemail.php">
> <label for="subject">Subject of email:</label><br />
> <input id="subject" name="subject" type="text"
> value="<?php
> echo $subject;?>"><br />
> <label for="elvismail">Body of email:</label><br />
> <textarea id="elvismail" name="elvismail" rows="8"
> cols="40">"<?php echo $text;?>" </textarea><br
> />
> <input type="submit" name="Submit" value="Submit" />
> </form>';
You don't need the nested echoes. Just concatenate instead:
echo '<br /><br />
<form method="post" action="sendemail.php">
<label for="subject">Subject of email:</label><br />
<input id="subject" name="subject" type="text"
value="' . $subject . '"><br />
<label for="elvismail">Body of email:</label><br />
<textarea id="elvismail" name="elvismail" rows="8"
cols="40">"' . $text . '" </textarea><br />
<input type="submit" name="Submit" value="Submit" />
</form>';
In short you're doing this :
echo 'Some HTML text here ' . $subject . ' some more HTML text ' . $text .
' and finally other stuff here';
--
Cheers -- Tim