php 在变量之间添加空格
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/10519653/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
adding spaces between variables
提问by Erica Horvatin
I am doing a project for class, and I need to simply put a space between the city state country and zip variables. Please help! Thank you!
我正在做一个班级项目,我需要简单地在城市状态国家和 zip 变量之间放置一个空格。请帮忙!谢谢!
The code looks like this:
代码如下所示:
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>";
回答by gunnx
echo echo ' ';after any echo line you want to add a space.
回声echo ' ';任何回音行后要添加一个空格。
Or as stated in commments:
或如评论中所述:
"There's no need for a non-breaking space. A regular
echo " ";will be fine. – ceejayoz May 9 '12 at 16:01"
“不需要一个不间断的空间。一个普通的
echo " ";就可以了。 – ceejayoz 2012 年 5 月 9 日 16:01”
回答by Luchian Grigore
How about
怎么样
echo $weather['current_observation']['display_location']['city'];
echo ' ';
echo $weather['current_observation']['display_location']['state'];
回答by Karo
You can just add spaces this way
你可以这样添加空格
echo $weather['current_observation']['display_location']['city'] . " ";
echo $weather['current_observation']['display_location']['city'] . " ";
回答by ceejayoz
At its simplest:
最简单的:
echo " ";
If that's not doing the trick, you've left important details out of your question.
如果这不起作用,那么您就忽略了重要的细节。
回答by amindfv
You can add on to the end of a string with .
您可以添加到字符串的末尾 .
So "foo" . "bar"returns "foobar"
所以"foo" . "bar"返回"foobar"
I would write
我会写
echo $weather['current_observation']['display_location']['city'] . ' ';
echo $weather['current_observation']['display_location']['state'] . ' ';
回答by nimish
For normal space do.
对于普通空间做。
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'] . " ";
or for HTML spacing do.
或为 HTML 间距做。
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'] . " ";

