Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 11 of 11
  1. #1
    New Coder
    Join Date
    Jul 2005
    Posts
    83
    Thanks
    0
    Thanked 0 Times in 0 Posts

    irregular bbcode

    I Have regexp replacements in order to have working bbcode on the site.
    But I also want to include new tag [no][/no] which will remove any codes inside of itself (ie write them as text). It's easy in theory - just to grab everything inside NO tag and replace all "[" and "]" to their html codes (ie [ and &#93.
    Anyone can help me in practice here plz?
    It doesn't have to be a regexp, i can do replacement b4 everything else, cuz regexp may actually slow down performance in this case.

  • #2
    Regular Coder
    Join Date
    May 2006
    Location
    Wales
    Posts
    820
    Thanks
    1
    Thanked 82 Times in 79 Posts
    PHP Code:
    $string '';
    $search = array('['']');
    $replace = array(''''); // put in html codes
    preg_replace('/\[no\](.*?)\[\/no\]/is'str_replace($search$replace'$1'$string); 
    ok try that... not sure though

  • #3
    New Coder
    Join Date
    Jul 2005
    Posts
    83
    Thanks
    0
    Thanked 0 Times in 0 Posts
    i appreciate your reply, at least someone =)
    That's what I've inserted b4 my code
    Code:
    $searchforno = array('[', ']');
    $replaceforno = array('[', ']');
    $string = preg_replace('/\[no\](.*?)\[\/no\]/is', str_replace($searchforno, $replaceforno, '$1', $string));
    Unfortunatly, now it won't output anything at all though.

  • #4
    New Coder
    Join Date
    Jul 2005
    Posts
    83
    Thanks
    0
    Thanked 0 Times in 0 Posts
    anyone else can help maybe?

  • #5
    Regular Coder
    Join Date
    May 2006
    Location
    Wales
    Posts
    820
    Thanks
    1
    Thanked 82 Times in 79 Posts
    PHP Code:
    $string '';
    $search = array('['']');
    $replace = array(''''); // put in html codes
    echo preg_replace('/\[no\](.*?)\[\/no\]/is'str_replace($search$replace'$1'), $string); 

  • #6
    Senior Coder
    Join Date
    Aug 2003
    Location
    One step ahead of you.
    Posts
    2,815
    Thanks
    0
    Thanked 3 Times in 3 Posts
    That shouldn't work as str_replace() will be executed before the preg_replace.
    I'm not sure if this was any help, but I hope it didn't make you stupider.

    Experience is something you get just after you really need it.
    PHP Installation Guide Feedback welcome.

  • #7
    New Coder
    Join Date
    Jul 2005
    Posts
    83
    Thanks
    0
    Thanked 0 Times in 0 Posts
    yeah it didn't really do anything

  • #8
    New Coder
    Join Date
    Jul 2005
    Posts
    83
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by marek_mar
    That shouldn't work as str_replace() will be executed before the preg_replace.
    how will it work though

  • #9
    Regular Coder
    Join Date
    May 2006
    Location
    Wales
    Posts
    820
    Thanks
    1
    Thanked 82 Times in 79 Posts
    hmmm

    PHP Code:
    while (preg_match('/\[no\].*?\].*?\[\/no\]/is'$string)){
    $string preg_replace('/\([no\].*?)\](.*?\[\/no\])/is''$1 ]$2'$string);
    }
    while (
    preg_match('/\[no\].*?\[.*?\[\/no\]/is'$string)){
    $string preg_replace('/\([no\].*?)\[(.*?\[\/no\])/is''$1[ $2'$string);

    Maybe that will do the trick (hopefully).

  • #10
    Senior Coder
    Join Date
    Aug 2003
    Location
    One step ahead of you.
    Posts
    2,815
    Thanks
    0
    Thanked 3 Times in 3 Posts
    PHP Code:
    preg_replace_callback('/\[no\].*?\].*?\[\/no\]/is'create_function('$matches''return str_replace($search, $replace, $matches[0]);'), $string); 
    I'm not sure if this was any help, but I hope it didn't make you stupider.

    Experience is something you get just after you really need it.
    PHP Installation Guide Feedback welcome.

  • #11
    New Coder
    Join Date
    Jul 2005
    Posts
    83
    Thanks
    0
    Thanked 0 Times in 0 Posts
    have another function worked. With preg_replace_callback.
    Thanks all =)


  •  

    Posting Permissions

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