...

View Full Version : irregular bbcode



sushestvo
08-22-2006, 07:55 PM
I Have regexp replacements in order to have working bbcode on the site.
But I also want to include new tag 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.

Mwnciau
08-23-2006, 12:20 AM
$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

sushestvo
08-23-2006, 03:02 PM
i appreciate your reply, at least someone =)
That's what I've inserted b4 my 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. :confused:

sushestvo
08-28-2006, 04:40 PM
anyone else can help maybe? :confused:

Mwnciau
08-28-2006, 07:58 PM
$string = '';
$search = array('[', ']');
$replace = array('', ''); // put in html codes
echo preg_replace('/\[no\](.*?)\[\/no\]/is', str_replace($search, $replace, '$1'), $string);

marek_mar
08-28-2006, 09:24 PM
That shouldn't work as str_replace() will be executed before the preg_replace.

sushestvo
08-30-2006, 04:56 PM
yeah it didn't really do anything :(

sushestvo
08-30-2006, 04:57 PM
That shouldn't work as str_replace() will be executed before the preg_replace.
how will it work though :confused:

Mwnciau
08-30-2006, 05:25 PM
hmmm



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).

marek_mar
08-30-2006, 06:49 PM
preg_replace_callback('/\[no\].*?\].*?\[\/no\]/is', create_function('$matches', 'return str_replace($search, $replace, $matches[0]);'), $string);

sushestvo
08-30-2006, 09:14 PM
have another function worked. With preg_replace_callback.
Thanks all =)



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum