Hi there,

I want to create a function which will replace certain words out of a text with internal links. That works so far, but if I have two matches, I end up with invalid html code.

Welpen                  /hunde
Chihuahua Welpen        /hunde,chihuahua

function seo_internal_links($str, $links, $limit) {
        foreach($links AS $link){
                $pattern[$k] = "~\b($link[phrase])\b~i";
                $replace[$k] = '<a href="'.$link[link].'">\\1</a>';
        return preg_replace($pattern,$replace,$str, $limit);

seo_internal_links($ad[text], $seo_internal_links, $limit = 1);

This will result in:
<a href="//hunde,chihuahua">Chihuahua <a href="/hunde">Welpen</a></a>

Has somebody an idea on how to avoid this? I would also like to limit the amount of hits, but the limit in preg_replace accounts only for unique words, not the whole array.

Thank you for any hint,


PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to