Go Back   CodingForums.com > :: Server side development > PHP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 08-22-2006, 06:55 PM   PM User | #1
sushestvo
New Coder

 
Join Date: Jul 2005
Posts: 83
Thanks: 0
Thanked 0 Times in 0 Posts
sushestvo is an unknown quantity at this point
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.
sushestvo is offline   Reply With Quote
Old 08-22-2006, 11:20 PM   PM User | #2
Mwnciau
Regular Coder

 
Join Date: May 2006
Location: Wales
Posts: 820
Thanks: 1
Thanked 82 Times in 79 Posts
Mwnciau is on a distinguished road
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
Mwnciau is offline   Reply With Quote
Old 08-23-2006, 02:02 PM   PM User | #3
sushestvo
New Coder

 
Join Date: Jul 2005
Posts: 83
Thanks: 0
Thanked 0 Times in 0 Posts
sushestvo is an unknown quantity at this point
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.
sushestvo is offline   Reply With Quote
Old 08-28-2006, 03:40 PM   PM User | #4
sushestvo
New Coder

 
Join Date: Jul 2005
Posts: 83
Thanks: 0
Thanked 0 Times in 0 Posts
sushestvo is an unknown quantity at this point
anyone else can help maybe?
sushestvo is offline   Reply With Quote
Old 08-28-2006, 06:58 PM   PM User | #5
Mwnciau
Regular Coder

 
Join Date: May 2006
Location: Wales
Posts: 820
Thanks: 1
Thanked 82 Times in 79 Posts
Mwnciau is on a distinguished road
PHP Code:
$string '';
$search = array('['']');
$replace = array(''''); // put in html codes
echo preg_replace('/\[no\](.*?)\[\/no\]/is'str_replace($search$replace'$1'), $string); 
Mwnciau is offline   Reply With Quote
Old 08-28-2006, 08:24 PM   PM User | #6
marek_mar
Sensei


 
Join Date: Aug 2003
Location: One step ahead of you.
Posts: 2,815
Thanks: 0
Thanked 3 Times in 3 Posts
marek_mar is on a distinguished road
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.
marek_mar is offline   Reply With Quote
Old 08-30-2006, 03:56 PM   PM User | #7
sushestvo
New Coder

 
Join Date: Jul 2005
Posts: 83
Thanks: 0
Thanked 0 Times in 0 Posts
sushestvo is an unknown quantity at this point
yeah it didn't really do anything
sushestvo is offline   Reply With Quote
Old 08-30-2006, 03:57 PM   PM User | #8
sushestvo
New Coder

 
Join Date: Jul 2005
Posts: 83
Thanks: 0
Thanked 0 Times in 0 Posts
sushestvo is an unknown quantity at this point
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
sushestvo is offline   Reply With Quote
Old 08-30-2006, 04:25 PM   PM User | #9
Mwnciau
Regular Coder

 
Join Date: May 2006
Location: Wales
Posts: 820
Thanks: 1
Thanked 82 Times in 79 Posts
Mwnciau is on a distinguished road
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).
Mwnciau is offline   Reply With Quote
Old 08-30-2006, 05:49 PM   PM User | #10
marek_mar
Sensei


 
Join Date: Aug 2003
Location: One step ahead of you.
Posts: 2,815
Thanks: 0
Thanked 3 Times in 3 Posts
marek_mar is on a distinguished road
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.
marek_mar is offline   Reply With Quote
Old 08-30-2006, 08:14 PM   PM User | #11
sushestvo
New Coder

 
Join Date: Jul 2005
Posts: 83
Thanks: 0
Thanked 0 Times in 0 Posts
sushestvo is an unknown quantity at this point
have another function worked. With preg_replace_callback.
Thanks all =)
sushestvo is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
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

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 12:44 PM.


Advertisement
Log in to turn off these ads.