PHP echo 添加空格
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/15353389/
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
PHP echo add spaces
提问by Patrick
How do I get some empty spaces after the current logged in user first name is displayed? Just need a few spaces because it's running into something else.
显示当前登录的用户名后如何获得一些空格?只需要几个空格,因为它遇到了别的事情。
<?php
if ( is_user_logged_in() ) {
global $current_user;
get_currentuserinfo();
echo '<span class="white-text">Welcome, ' .$current_user->user_firstname . "</span>\n";}
?>
采纳答案by icktoofay
A better way would be not to add more spaces, but add a margin:
更好的方法不是添加更多空格,而是添加边距:
<span class="white-text" style="margin-right: 5em;">
Change 5emto some other number to change the amount of space.
更改5em为其他数字以更改空间量。
回答by Scott Yang
echo '<span class="white-text">Welcome, ' .$current_user->user_firstname . " </span>\n";
each is a "non-breaking space"
每个 是一个“不间断空间”
回答by Jay Huang
Your code isn't working because the extra spaces are ignored, this is normal. Only the first space character will be outputted, if you want more, use (non-breaking space).
您的代码不起作用,因为多余的空格被忽略,这是正常的。只会输出第一个空格字符,如果需要更多,请使用 (不间断空格)。
You can also put a margin on the text with CSS:
您还可以使用 CSS 在文本上放置边距:
span.white-text {
margin: 5px;
}
回答by John Mead
I've been faced with a similar problem and after much trial and error found that this works for my code line, inserting a space between First Name and Surname - so something similar may well work for yours...
我遇到过类似的问题,经过多次反复试验发现这适用于我的代码行,在名字和姓氏之间插入一个空格 - 所以类似的东西可能对你有用......
<option value=<?php echo $row ["First_Name"], " ", $row["Surname"] ; ?>>
回答by Jun Lan
echo "<td>" . $info['id'] . "</td>";
echo "<td></td>";
echo "<td></td>";
echo "<td>" . $info['refid'] . "</td>";
echo "<td></td>";
echo "<td></td>";
echo "<td>" . $info['username'] . "</td>";
回答by Sumit Bijvani
try this
尝试这个
echo "<span class='white-text'>Welcome," . " " .$current_user->user_firstname."</span>\n";

