Re: embedding php inside of php

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



If you are using PHP 5.4 or short_open_tag is 1, you can also do this:

Some HTML text here<?=subject?>some more HTML text<?=$text?>and finally other stuff here


Am 01.07.2012 14:01, schrieb Tim Streater:
> On 01 Jul 2012 at 01:00, Tim Dunphy <bluethundr@xxxxxxxxx> 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
>
>
>



[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux