using php tags inside echo

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
deejay
Forum Contributor
Posts: 201
Joined: Wed Jan 22, 2003 3:33 am
Location: Cornwall

using php tags inside echo

Post by deejay »

hi

what i am trying to do should be really simple but i just cant get it to work. I am trying to put a form (which i have working on a .php page but can not get it to repeat correctly) inside an echo command.

i have tried

echo ('<form name="login" method="post" action=" <?php echo $PHP_SELF ?>">
<font class="whiteHeader">
username:
<input type="text" name="username">
<br>
password:
<input type="password" name="user_password">
<br>
<input type="submit" value="submit">
</font>
</form>

');


as well as putting it inside ("") and \ escapes. ending with " . before <?php. but i cannot get it to work. and using herdoc, none of which i can get to run. The problem is the way in which it handles going back into php. Have read the chapters regarding this a couple of times but still cant work out what I am doing wrong. How would solve this? if any one has some code that they have written to do something similar I'm sure I could see what I am doing wrong.

Thanks

Deej
User avatar
twigletmac
Her Royal Site Adminness
Posts: 5371
Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK

Post by twigletmac »

Try:

Code: Select all

echo '<form name="login" method="post" action="'.$PHP_SELF.'"> 
<font class="whiteHeader"> 
username: 
<input type="text" name="username"> 
<br> 
password: 
<input type="password" name="user_password"> 
<br> 
<input type="submit" value="submit"> 
</font> 
</form>';
You cannot echo() within an echo(), instead you need to concenate the string and the variable.

More info:
http://www.php.net/manual/en/language.o ... string.php

Mac
User avatar
deejay
Forum Contributor
Posts: 201
Joined: Wed Jan 22, 2003 3:33 am
Location: Cornwall

Post by deejay »

thanks :-) now works

i had tried that before but had an extra } in the function that was giving me the problems ( doh!)
Post Reply