开发者

how to resplace a word with hyperlink in a string

开发者 https://www.devze.com 2023-03-31 18:22 出处:网络
i am trying to build a function to change a word into a hyper link. i used this function function myseo($t){

i am trying to build a function to change a word into a hyper link. i used this function

function myseo($t){
$url = 'http://' . $_SERVER['SERVER_NAME'] . $_SERVER[开发者_如何学JAVA'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;
}

but it doesnt work with me.

regards Piny


I think it got scared, because it works with me now. ;)

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


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

should be

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

and try again

0

精彩评论

暂无评论...
验证码 换一张
取 消