Enjoy an ad free experience by logging in. Not a member yet?
Register .
08-22-2006, 06:55 PM
PM User |
#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 ]).
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.
08-22-2006, 11:20 PM
PM User |
#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
08-23-2006, 02:02 PM
PM User |
#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.
08-28-2006, 03:40 PM
PM User |
#4
New Coder
Join Date: Jul 2005
Posts: 83
Thanks: 0
Thanked 0 Times in 0 Posts
anyone else can help maybe?
08-28-2006, 06:58 PM
PM User |
#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 );
08-28-2006, 08:24 PM
PM User |
#6
Sensei
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.
08-30-2006, 03:56 PM
PM User |
#7
New Coder
Join Date: Jul 2005
Posts: 83
Thanks: 0
Thanked 0 Times in 0 Posts
yeah it didn't really do anything
08-30-2006, 03:57 PM
PM User |
#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
08-30-2006, 04:25 PM
PM User |
#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).
08-30-2006, 05:49 PM
PM User |
#10
Sensei
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.
08-30-2006, 08:14 PM
PM User |
#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 =)
Jump To Top of Thread
Thread Tools
Rate This Thread
Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
All times are GMT +1. The time now is 12:44 PM .
Advertisement
Log in to turn off these ads.