Jump to content

Formatting Issue


unemployment

Recommended Posts

echo '<a href="/u/'. $user_info["username"] .'"><img src="'. getUserAvatar($user_info['username']) .'" class="avatar f_left small" title="'. $user_info['display_name'] .'" alt="'.$user_info['display_name'].'" /></a>'; 

// OR 

echo '<a href="/u/', $user_info["username"], '"><img src="', getUserAvatar($user_info['username']), '" class="avatar f_left small" title="', $user_info['display_name'], '" alt="', $user_info['display_name'], '" /></a>'; 

// OR wrapped in double quotes...

echo "<a href=\"/u/{$user_info["username"]}\"><img src=\"", getUserAvatar($user_info['username']), "\" class=\"avatar f_left small\" title=\"{$user_info['display_name']}\" alt=\"{$user_info['display_name']}\" /></a>"; 

 

Note:  that the comas and the periods are not doing the same thing, even though the output may be the same.

 

Although you can use single and double quotes, try to stick to one as your "outside" wrappers to minimize confusion.

Link to comment
Share on other sites

I tend to use single quotes for html output...  This allows me to use the double quotes for html elements without having to think about it much and place variables outside of the single quotes to get them to work properly like:

 

<?php
...

echo '<a href="/u/' . $user_info['username'] . '">
       <img src="' . getUserAvatar($user_info['username']) . '" 
        class="avatar f_left small" 
        title="' . $user_info['display_name'] . '" 
        alt="' . $user_info['display_name'] . '" /></a>'; 

?>

Link to comment
Share on other sites

Single quotes output what is literally between them.

 

$foo = 'bar';

echo 'foo $foo';

 

So this would echo "foo $foo".

 

Double quotes will parse variables and functions within the string.

$foo = 'bar';

echo "foo $foo";

 

So this would echo "foo bar".

 

If you want to use variables inside single quotes you have to concatenate.

 

 

$foo = 'bar';

echo 'foo ' . $foo;

 

This would echo "foo bar".

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.