fork download
  1. <?php
  2. // Easy HashTag converter
  3.  
  4.  
  5. // this is only for error prevent in this ideone.
  6. // url helper is used in Laravel framework.
  7. function url($string)
  8. {
  9. return $string;
  10. }
  11.  
  12. // convert Hashtag to clickable url.
  13. function convertHashtags($string)
  14. {
  15. $regex = "/#+([a-zA-Z0-9_]+)/";
  16. return preg_replace($regex, '<a href="' . url('search-tag/$1') . '">$0</a>', $string);
  17. }
  18.  
  19. echo convertHashtags("#123456 I am #successful hashtag #converter and I am #cool!");
Success #stdin #stdout 0.03s 25780KB
stdin
Standard input is empty
stdout
<a href="search-tag/123456">#123456</a> I am <a href="search-tag/successful">#successful</a> hashtag <a href="search-tag/converter">#converter</a> and I am <a href="search-tag/cool">#cool</a>!