Forum String Replacements

A

Anonymous

Guest
making enter = <br>
use this function:
Code:
nl2br()

use preg_replace() for urls
there should be some documentation for that somewhere
 
Take this simple example on URL parsing:
Code:
<?php

function ParseBBCode($code) {

     $preg = array(	
          '#\[url\]www\.(.*?)\[/url\]#si'     => '<a href="http://www.\\1">\\1</a>',
          '#\[url\](.*?)\[/url\]#si'               => '<a href="\\1">\\1</a>',
          '#\[url=(.*?)\](.*?)\[/url\]#si'      => '<a href="\\1">\\2</a>'
          // More tags can be added
     );

     return preg_replace(array_keys($preg), array_values($preg), $code);

}

?>
 
Like Virtuoso said, use the PHP's nl2br() function.
My code works great with me... make sure you pass something with an URL inside.
 
Back
Top