Html存在字符前的制表符
问题描述:
I am printing some names in PHP. However is always exist a tab character at the begin and end of string . How can I remove the tab character. Here is my code, it still cannot remove the extra tab.
<strong>
<?php
for ($i=0;$i <count($countrys);$i++){
$country = preg_replace('/[\s]+/mu', ' ', $countrys[$i]);
$country = trim($country);
echo $country;
if ($i != count($countrys)-1){
echo ', ';
}
}
?>
</strong>
The outcome of the printing is like this.
" China, England, USA "
我在PHP中打印一些名称。 但是,在字符串的开头和结尾始终存在制表符。 如何删除制表符。 这是我的代码,它仍然无法删除额外的标签。 p>
&lt; strong&gt;
&lt;?php
for($ i = 0; $ i&lt; count($ countrys); $ i ++){
$ country = preg_replace('/ [\ s] + / mu','',$ countrys [$ i]);
$ country = trim($ country);
echo $ country;
if($ i!= count($ countrys)-1){
echo',';
}
}
?
?&gt;
&lt; / strong&gt;
code> pre>
打印结果如下。 p>
“China,England,USA”
pre>
div>
答
Be careful the space between html Tag and php code, browser will read the space between html tag and php echo
So just render it in one row
<strong><?php $countrys = ['a','v']; for ($i=0;$i<count($countrys);$i++){ $country = $countrys[$i]; echo $country; if ($i != count($countrys)-1){ echo ', '; } } ?></strong>
You can simply to check your raw html source after rendering to prevent unexpected space or row