Re: preg_replace question

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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

[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux