2011-08-27 108 views
1

我正在尝试构建将单词更改为超链接的功能。我用这个功能如何用字符串中的超链接替换单词

function myseo($t){ 
$url = 'http://' . $_SERVER['SERVER_NAME'] . $_SERVER['REQUEST_URI']; 
$a=array('kid','children'); 
$uu=count($a); 
for ($i = 1; $i <= $uu; $i++) {  
$theseotext= str_replace($a[$i], '<a href="'.$url[$i].'">'.$a[$i].'</a>', $t); 
} 
return $theseotext; 
} 

但它不和我一起工作。

问候 松树的

回答

3

我觉得很害怕,因为它现在和我一起工作。 ;)

function myseo($t){ 
    $url = 'http://' . $_SERVER['SERVER_NAME'] . $_SERVER['REQUEST_URI']; 
    $a = array('kid', 'children'); 
    $uu = count($a); 
    $theseotext = $t; 
    for ($i = 0; $i < $uu; $i++) { 
     $theseotext = str_replace($a[$i], '<a href="'.$url.'">'.$a[$i].'</a>', $theseotext); 
    } 
    return $theseotext; 
} 

Demo

+0

感谢..现在它的工作....但为什么它是害怕,亲爱的...! –

+0

@Pin Cody:我不知道它为什么会害怕,但我的理论是,它是一个孩子。你看,它取代了孩子和孩子,它必须是一个这样做。 :D – Shef

+0

哈哈哈亲爱的* _ ^ –

0
$theseotext= str_replace($a[i], '<a href="'.$url[i].'">'.$a[i].'</a>', $t); 

应该

$theseotext= str_replace($a[$i], '<a href="'.$url.'">'.$a[$i].'</a>', $t); 

,然后再试一次