preg_replace full words by link

Discussion in 'PHP' started by tgkprog, Jul 22, 2008.

  1. #1
    function splitHtmlTextOnlyProc($s, &$curr, &$nxt){
    	$t=1;
    
    	global $ll;
    
    	if(($curr - $nxt) == 0)return;
    
    	$words = preg_split("/[\s,]+/", substr($s, $curr, $nxt - $curr));
    
    	foreach($words as $k ){
    		if(trim($k)=='')continue;
    		$k1 = getLink($k);
    
    		if($k != $k1){
    
    			$count = 0;
    			$kq = preg_quote($k);
    			$s =  preg_replace ( "/\b" . $kq . "\b/i", $k1 , $s, -1, $count);
    			//$s = str_replace($k, $k1, $s, $count);
    			//$s =  preg_replace ( "/" . $k . "/", $k1 , $s, -1, $count);
    			$lNxt= $nxt ;
    			$nxt += (strlen($k1) - strlen($k)) * $count;
    			log2("splitadd lNxt $lNxt nxt $nxt count $count k \n$k\n k1 \n$k1\n\n");
    		}
    
    	}
    
    	return $s;
    
    }
    PHP:
    this function takes a string parses it out to words, sends each word to getLink which caches words and returns a replacement a href link or the orignal word.

    is this the best way to do this? is there some case where there might be a problem?

    thank you
     
    tgkprog, Jul 22, 2008 IP