2012-05-09 48 views
-5

我正在做一个类的项目,我只需要在城邦状态国家和zip变量之间加一个空格。请帮忙!谢谢!在变量之间加上空格

的代码看起来是这样的:

echo "<p>"; 
echo $weather['current_observation']['display_location']['city']; 
echo $weather['current_observation']['display_location']['state']; 
echo $weather['current_observation']['display_location']['country']; 
echo $weather['current_observation']['display_location']['zip']; 
echo "</p><p>"; 
echo $weather['current_observation']['observation_time_rfc822']; 
echo "</p><p>"; 
echo $weather['current_observation']['weather']; 
echo "</p><p>"; 
echo $weather['current_observation']['temperature_string']; 
echo "</p><p>"; 
echo $weather['current_observation']['wind_string']; 
echo "</p>"; 
+2

你似乎没有甚至试图添加一个空格... –

+1

哇...编辑战争... –

+1

@FelixKling:皮尤皮尤皮尤 –

回答

2

如何你想添加一个空格任何回音线后约

echo $weather['current_observation']['display_location']['city']; 
echo ' '; 
echo $weather['current_observation']['display_location']['state']; 
5

回声echo '&nbsp';

或在commments说:

“没有必要非打破空间定期echo " ";将被罚款 - 在16:01 ceejayoz 5月9日'12。”

+0

这工作!非常感谢你! –

+2

不需要非破坏性空间。一个常规的'echo“;'会没事的。 – ceejayoz

1

您可以添加到字符串的结尾与.

所以"foo" . "bar"回报"foobar"

我会写

echo $weather['current_observation']['display_location']['city'] . ' '; 
echo $weather['current_observation']['display_location']['state'] . ' '; 
2

你可以只添加空格这样

echo $weather['current_observation']['display_location']['city'] . " ";

1

在最简单的:

echo " "; 

如果没有做的伎俩,你留下你的问题的重要细节。

-1

对于正常空间来说。

echo $weather['current_observation']['display_location']['city'] . " "; 
echo $weather['current_observation']['display_location']['state'] . " "; 
echo $weather['current_observation']['display_location']['country'] . " "; 
echo $weather['current_observation']['display_location']['zip'] . " "; 

或者用于HTML间距。

echo $weather['current_observation']['display_location']['city'] . "&nbsp;"; 
echo $weather['current_observation']['display_location']['state'] . "&nbsp;"; 
echo $weather['current_observation']['display_location']['country'] . "&nbsp;"; 
echo $weather['current_observation']['display_location']['zip'] . "&nbsp;"; 
+2

你需要'.',而不是'+'。 :-P –

+1

“HTML间距”有点令人误解。两者都是HTML间距。 – ceejayoz

+0

@火箭我编辑我的评论..我想现在它不应该为负面评价金额:D – nimish