3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?php $text = "This is a #hashtag within some #awesometext."; function tagIt($body) { $string = $body; $htag = "#"; $arr = preg_split("/\s|\./", $string);print_r($arr); $arrc = count($arr); $i = 0; while($i < $arrc) { if(substr($arr[$i], 0, 1) === $htag) { $arr[$i] = "<a href = 'category.php?tag=".substr($arr[$i], 1)."'>".$arr[$i]."</a>"; } $i++; } $string = implode(" ", $arr); echo "\n".$string."\n"; } tagIt($text);
Output for 4.3.0 - 7.1.0
Array ( [0] => This [1] => is [2] => a [3] => #hashtag [4] => within [5] => some [6] => #awesometext [7] => ) This is a <a href = 'category.php?tag=hashtag'>#hashtag</a> within some <a href = 'category.php?tag=awesometext'>#awesometext</a>