I have a comma separated string, which consists of a list of tags and want to convert it to array to get a link for every tag.
Example:
$string = \'h
Another solution:
$html = trim(preg_replace('/([^,]+)/', ' \1', $string));
Or if you have to html encode the tags (always smart, since you're creating html from text):
$html = trim(preg_replace_callback('/([^,]+)/', function($match) {
$tag = $match[1];
return ' ' . htmlspecialchars($tag) . '';
}, $string));
So this $string
would work too: "tag with space,html,css,php,mysql,javascript"
More regex is always good!