2015-07-11 21 views
0
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++;       
    } 
} 

我是一個初學者,我想做一個hashtag finder功能。我的php標籤標識符功能不起作用

我想這樣做,但它看起來像我不能使用對象和數組來定義鍵。

回答

0
function convertHashtags($str) { 
    $regex = "/#+([a-zA-Z0-9_]+)/"; 
    $str = preg_replace($regex, '<a href="insert taglink">$0</a>', $str); 
    return($str); 
} 
0

這段代碼在一個字符串返回所有的#哈希標籤數組:

$str= 'your string with a #hashtag inside'; 
    preg_match_all('/#\w+/', $str, $match); 
    var_dump($match); /* print the result */ 
+0

非常感謝你:d。 – AyKenDuu