Hi there,

I am trying to replace certain words inside a text with php. Unfortunatelly my function is creating invalid html as output.

For example the words "beagle" and "welpen" have to be replaced inside this text: "süße knuffige Beagle Welpen ab sofort"

My result looks like this:
zwei süße knuffige <a href="/bsp/hunde,beagle">Beagle <a href="/bsp/hunde">Welpen</a></a>

The problem is, that my function is not closing the href tag before it starts to replace the next item.

Here is the code: ################################################################################################
        // create internal links
        function internal_links($str, $links, $limit) {
                foreach($links AS $link){
                        $pattern[$k] = "~\b($link[phrase])\b~i";
                        $replace[$k] = '<a href="'.$link[link].'">\\1</a>';
                        $k++;
                }
                return preg_replace($pattern,$replace,$str, $limit);
        }
        
################################################################################################I

I could not find a way to fix this and I would be happy for some help. Thank you in advance!

Merlin

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

Reply via email to