-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>";
4

6 回答 6

7

echo '&nbsp';在要添加空格的任何回显线之后回显。

或如评论中所述:

“不需要不间断的空间。常规echo " ";就可以了。- ceejayoz 2012 年 5 月 9 日 16:01”

于 2012-05-09T15:57:46.550 回答
3

怎么样

echo $weather['current_observation']['display_location']['city']; 
echo ' ';
echo $weather['current_observation']['display_location']['state']; 
于 2012-05-09T15:57:41.120 回答
2

您可以通过这种方式添加空格

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

于 2012-05-09T15:58:43.670 回答
1

最简单的:

echo " ";

如果这不能解决问题,那么您已经将重要的细节排除在您的问题之外。

于 2012-05-09T16:01:02.413 回答
1

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

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

我会写

echo $weather['current_observation']['display_location']['city'] . ' '; 
echo $weather['current_observation']['display_location']['state'] . ' ';
于 2012-05-09T15:58:42.533 回答
-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;";
于 2012-05-09T16:01:24.373 回答