$tags="раз
два
три";
$str = '';
foreach (split("\n", $tags) as $tag) {
if (strlen(trim($tag)) == 0) continue;
$str .= '<a href="#">'. $tag . '</a>';
}
Warning
This function was DEPRECATED in PHP 5.3.0, and REMOVED in PHP 7.0.0.
Alternatives to this function include:
preg_split()
explode()
str_split()