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