Home > front end >  How can I add a character space after the tags function in PHP
How can I add a character space after the tags function in PHP

Time:12-30

I am using this code

<span >
    <? echo ($rrow['tags']) ? $rrow['tags'] : "-"; ?>
</span> 

to pull tags and list them, at the moment it shows up like this

Tags: tag1,tag2,tag3,tag4

but I would like there to be a space after the comas such as

Tags: tag1, tag2, tag3, tag4

I tried a few different solutions but I am not expert with code.Thanks

CodePudding user response:

You can use str_replace() for this:

<?php echo str_replace(',',', ', $rrow['tags']);

Sample output: https://3v4l.org/QSXCR

CodePudding user response:

Just use string replace function and replace , with , (comma with space)

<span ><? echo ($rrow['tags']) ? str_replace(',', '&nbsp;', $rrow['tags']); : "-"; ?></span>

I hope this work for you

  • Related