3v4l.org

run code in 300+ PHP versions simultaneously
<?php function convertHashtags($str) { $regex = '/@([a-zA-Z0-9]+[\sa-zA-Z0-9]*)/'; if(preg_match($regex,$str,$matches) === 1){ list($username,$name) = [$matches[0] , strtolower(str_replace(' ','',$matches[1]))]; return "<a href='profile?id=$name'>$username</a>"; } throw new Exception('Unable to find username in the given string'); } $string = 'I am @Marie Lee, nice to meet you!'; $string = convertHashtags($string); echo $string;

preferences:
29.03 ms | 406 KiB | 5 Q