3v4l.org

run code in 300+ PHP versions simultaneously
<?php $body = "Text text #hashtag text text #hast/tag"; $hashtag_path = '/path/to'; $hashtags_url = '/#(\S+)/'; $body = preg_replace_callback( $hashtags_url, function($matches) use ($hashtag_path) { return "<a href=\"$hashtag_path/hashtag/".urlencode($matches[1])."\">".$matches[0]."</a>"; }, $body); echo $body;

preferences:
72.06 ms | 405 KiB | 5 Q