当前位置: 动力学知识库 > 问答 > 编程问答 >

php - adding spaces between variables

问题描述:

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!

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

网友答案:

echo echo '&nbsp'; after any echo line you want to add a space.

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"

网友答案:

How about

echo $weather['current_observation']['display_location']['city']; 
echo ' ';
echo $weather['current_observation']['display_location']['state']; 
网友答案:

You can just add spaces this way

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

网友答案:

You can add on to the end of a string with .

So "foo" . "bar" returns "foobar"

I would write

echo $weather['current_observation']['display_location']['city'] . ' '; 
echo $weather['current_observation']['display_location']['state'] . ' ';
网友答案:

At its simplest:

echo " ";

If that's not doing the trick, you've left important details out of your question.

网友答案:

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.

 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;";
分享给朋友:
您可能感兴趣的文章:
随机阅读: