Format this!

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
mhouldridge
Forum Contributor
Posts: 267
Joined: Wed Jan 26, 2005 5:13 am

Format this!

Post by mhouldridge »

Hi,

I have the following code, which I cannot format to work.

Code: Select all

echo "Welcome ".$_SESSION['first_name'." ".$_SESSION['last_name']."<img src="images/1x1.gif" width="10"><a href="user_logout.php" class="10">Logout</a>';

I dont quite get the formatting side yet for html.


PLease help
User avatar
m3mn0n
PHP Evangelist
Posts: 3548
Joined: Tue Aug 13, 2002 3:35 pm
Location: Calgary, Canada

Post by m3mn0n »

You're missing a bracket on the first SESSION variable and you need to escape the double quotes if you're echoing with double quotes. And when you start an echo/print, make sure to finish it off with the same quote type. Single/Single or Double/Double, not Double/Single.
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post by John Cartwright »

User avatar
php3ch0
Forum Contributor
Posts: 212
Joined: Sun Nov 13, 2005 7:35 am
Location: Folkestone, Kent, UK

Post by php3ch0 »

The code you need is:

Code: Select all

echo "Welcome ".$_SESSION['first_name']." ".$_SESSION['last_name']."<img src='images/1x1.gif' width='10'><a href='user_logout.php' class='10'>Logout</a>";
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Post by Chris Corbyn »

If you're not already using an editor that does highlighting it might be an idea. Spotting mistakes like not escaping quotes sticks out like a sore thumb if you use one ;)
User avatar
m3mn0n
PHP Evangelist
Posts: 3548
Joined: Tue Aug 13, 2002 3:35 pm
Location: Calgary, Canada

Post by m3mn0n »

True. Syntax highlighting is very useful.
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post by John Cartwright »

Sami wrote:True. Syntax highlighting is very useful.
'

To some people, to others it is nothing more than a distraction :P
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Post by Chris Corbyn »

We're going off-topic here (my fault again :P) but if you use something like emacs you can turn highlighting on and off with just a few simple key presses. You can also stop it highlighting and simply do the bracket pairing. The rest of the time you can have plain old emacs.
Post Reply