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
https://forums.phpfreaks.com/topic/252396-formatting-issue/#findComment-1293999
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
https://forums.phpfreaks.com/topic/252396-formatting-issue/#findComment-1294000
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
https://forums.phpfreaks.com/topic/252396-formatting-issue/#findComment-1294019
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.