Without seeing the code that creates the arrays, it's tough to see the
problem. It looks like the first replacement is catching "Beagle Welpen"
entirely since the closing </a> tag gets placed after "Welpen". Then the
second replacement does just "Welpen".
Also, you should have quotes around "link" when building the $replace[]
entry since the array access is outside quotes. Finally, you don't need $k
here at all.
// create internal links
function internal_links($str, $links, $limit) {
foreach($links AS $link){
$pattern[] = "~\b($link[phrase])\b~i";
$replace[] = '<a href="'.$link['link'].'">\\1</a>';
}
return preg_replace($pattern,$replace,$str, $limit);
}
David