<?php
// Easy HashTag converter
// this is only for error prevent in this ideone.
// url helper is used in Laravel framework.
function url( $string )
{
return $string ;
}
// convert Hashtag to clickable url.
function convertHashtags( $string )
{
$regex = "/#+([a-zA-Z0-9_]+)/" ;
return preg_replace ( $regex , '<a href="' . url
( 'search-tag/$1' ) . '">$0</a>' , $string ) ; }
echo convertHashtags( "#123456 I am #successful hashtag #converter and I am #cool!" ) ;
PD9waHAKLy8gRWFzeSBIYXNoVGFnIGNvbnZlcnRlcgoKCi8vIHRoaXMgaXMgb25seSBmb3IgZXJyb3IgcHJldmVudCBpbiB0aGlzIGlkZW9uZS4KLy8gdXJsIGhlbHBlciBpcyB1c2VkIGluIExhcmF2ZWwgZnJhbWV3b3JrLgpmdW5jdGlvbiB1cmwoJHN0cmluZykKewoJcmV0dXJuICRzdHJpbmc7Cn0KCi8vIGNvbnZlcnQgSGFzaHRhZyB0byBjbGlja2FibGUgdXJsLgpmdW5jdGlvbiBjb252ZXJ0SGFzaHRhZ3MoJHN0cmluZykKewoJJHJlZ2V4ID0gIi8jKyhbYS16QS1aMC05X10rKS8iOwoJcmV0dXJuIHByZWdfcmVwbGFjZSgkcmVnZXgsICc8YSBocmVmPSInIC4gdXJsKCdzZWFyY2gtdGFnLyQxJykgLiAnIj4kMDwvYT4nLCAkc3RyaW5nKTsKfQoKZWNobyBjb252ZXJ0SGFzaHRhZ3MoIiMxMjM0NTYgSSBhbSAjc3VjY2Vzc2Z1bCBoYXNodGFnICNjb252ZXJ0ZXIgYW5kIEkgYW0gI2Nvb2whIik7