Announcement

Collapse
No announcement yet.

regex problem, could you help?

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • regex problem, could you help?

    I'm making a news script and I'd like to use vB Code in my script.

    here is my function text_to_html():
    PHP Code:
    function text_to_html($data) {
        
    $data trim ($data);
        
    $data strip_tags ($data);
        
    $data nl2br ($data);
        
        
    $patterns = array();
        
    $replacements = array();
        
    // [url]xxxx://www.mysite.com[/url] code..
        
    $patterns[0] = "#\[url\]([a-z]+?://){1}(.*?)\[/url\]#si";
        
    $replacements[0] = '<A HREF="\1\2" TARGET="_blank">\1\2</A>';
        
    // [url]www.mysite.com[/url] code.. (
        
    $patterns[1] = "#\[url\](.*?)\[/url\]#si";
        
    $replacements[1] = '<A HREF="http://\1" TARGET="_blank">\1</A>';
        
    // [url=xxxx://www.mynsite.com]MySiTE[/url] code..
        
    $patterns[2] = "#\[url=([a-z]+?://){1}(.*?)\](.*?)\[/url\]#si";
        
    $replacements[2] = '<A HREF="\1\2" TARGET="_blank">\3</A>';
        
    // [url=www.mysite.com]MySITE[/url] code..
        
    $patterns[3] = "#\[url=(.*?)\](.*?)\[/url\]#si";
        
    $replacements[3] = '<A HREF="http://\1" TARGET="_blank">\2</A>';
        
    // [email][email protected][/email] code...
        
    $patterns[4] = "#\[email\](.*?)\[/email\]#si";
        
    $replacements[4] = '<A HREF="mailto:\1">\1</A>';
        
    // [email=www.mijnsite.com]MySITE[/email] code..
        
    $patterns[5] = "#\[email=(.*?)\](.*?)\[/email\]#si";
        
    $replacements[5] = '<A HREF="mailto:\1">\2</A>';
        
    // [b]bold text[/b] code...
        
    $patterns[6] = "#\[b\](.*?)\[/b\]#si";
        
    $replacements[6] = '<B>\1</B>';
        
    // [i]italic text[/i] code...
        
    $patterns[7] = "#\[i\](.*?)\[/i\]#si";
        
    $replacements[7] = '<I>\1</I>';
        
    // [u]uderlined text[/u] code...
        
    $patterns[8] = "#\[u\](.*?)\[/u\]#si";
        
    $replacements[8] = '<U>\1</U>';
            
        
    $data preg_replace($patterns$replacements$data);
        
        return 
    $data;

    I also like to do the[list]-tag, but I don't understand regex
    So could someone do $patterns[9], $replacements[9] for me?

    Note: Use the 'quote'-button to see the above code whitout being mest up, is there no [offcode][/offcode] tag?


    thanks in advantage,

    Bob Day
widgetinstance 262 (Related Topics) skipped due to lack of content & hide_module_if_empty option.
Working...
X