function hashTagFinder($str)
{
$hash= explode(" ", substr($str, strpos($str, "#")));
$i=0;
foreach ($hash as $tag) {
$finder=substr_count($tag, "#");
if ($finder>=1 ) {
$fArray = array([$i]=> $tag);
}
$i++;
}
}
I am a beginner and I want to make a hashtag finder function.
I am trying to do it this way but it looks like I can't use object and arrays to define keys.
function convertHashtags($str) {
$regex = "/#+([a-zA-Z0-9_]+)/";
$str = preg_replace($regex, '<a href="insert taglink">$0</a>', $str);
return($str);
}
This code return an array with all #hashtags in a string:
$str= 'your string with a #hashtag inside';
preg_match_all('/#\w+/', $str, $match);
var_dump($match); /* print the result */