Page 2 of 2 FirstFirst 12
Results 11 to 17 of 17

Thread: Something like BBCODE

  1. #11
    Join Date
    Mar 2011
    Posts
    2,145
    Thanks
    59
    Thanked 116 Times in 113 Posts
    Blog Entries
    4

    Default

    check.php

    Code:
    <?php
    if(isset($_POST['textarea1'])) {
    $value = $_POST['textarea1'];
    include "bb.php";
    echo bb($value);
    }
    ?>
    <!DOCTYPE html>
    <html>
    <head>
    </head>
    <body>
    </body>
    </html>
    bb.php

    Code:
    <?php
    function bb($elem) {
    while(substr_count($elem, '[red]') > 0 and substr_count($elem, '[/red]') > 0) {
    $elem = preg_replace('[red]', '<span style="color:red">', $elem, 1); 
    $elem = preg_replace('[/red]', ',</span>', $elem, 1); 
    }
    return $elem; 
    }
    ?>
    $_POST['textarea1'] is [red]hello[/red]

    it outputs

    []hello[,]

    when I would like it to output

    hello

    any help?

  2. #12
    Join Date
    Mar 2011
    Posts
    2,145
    Thanks
    59
    Thanked 116 Times in 113 Posts
    Blog Entries
    4

    Default

    *BUMP*
    I'm still looking for an answer...

  3. #13
    Join Date
    Apr 2008
    Location
    So.Cal
    Posts
    3,643
    Thanks
    63
    Thanked 516 Times in 502 Posts
    Blog Entries
    5

    Default

    PHP Code:
    <?php
    $bbtext 
    "try [red]something[/red] like this";
    $find '#(\[red\])(.*)(\[/red\])#ui':
    $replace '<span style="color: red;">$2</span>';
    print 
    preg_replace$find,$replace,$bbtext );

  4. #14
    Join Date
    Mar 2011
    Posts
    2,145
    Thanks
    59
    Thanked 116 Times in 113 Posts
    Blog Entries
    4

    Default

    Is there any way to adapt that to work like this -

    PHP Code:
            $find[0] = '#(\[b\])(.*)(\[/b\])#ui';
            
    $find[1] = '#(\[i\])(.*)(\[/i\])#ui';
            
    $replace[0] = '<b>$2</b>';
            
    $replace[1] = '<i>$2</i>';
    for (
    $counter1 0$counter1 <= count($shortcut); $counter1 += 1) {
        
    $text preg_replace($find[$counter1],$replace[$counter1],$text); 


  5. #15
    Join Date
    Apr 2008
    Location
    So.Cal
    Posts
    3,643
    Thanks
    63
    Thanked 516 Times in 502 Posts
    Blog Entries
    5

    Default

    Don't need a loop - preg_replace can take arrays as its arguments.

  6. #16
    Join Date
    Apr 2012
    Location
    Chester, Cheshire
    Posts
    329
    Thanks
    7
    Thanked 35 Times in 35 Posts

    Default

    RocketTheme's RokCandy is on GPL licence, so you could pick that apart and work out the best way to get BBCode style functionality for a lot more complex things than bold and italic.

    http://www.rockettheme.com/extensions-joomla/rokcandy

  7. #17
    Join Date
    Mar 2011
    Posts
    2,145
    Thanks
    59
    Thanked 116 Times in 113 Posts
    Blog Entries
    4

    Default

    Quote Originally Posted by ApacheTech View Post
    RocketTheme's RokCandy is on GPL licence, so you could pick that apart and work out the best way to get BBCode style functionality for a lot more complex things than bold and italic.

    http://www.rockettheme.com/extensions-joomla/rokcandy
    Thanks Traq!

    Also, Apache Tech, I mentioned ealier in the thread that I only want s few basic bbcodes, not all of them - that's why I'm doing it this way...

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •