sushestvo 08-22-2006, 06: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-22-2006, 11:20 PM $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, 02: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, 03:40 PM anyone else can help maybe? :confused:
Mwnciau 08-28-2006, 06: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, 08:24 PM That shouldn't work as str_replace() will be executed before the preg_replace.
sushestvo 08-30-2006, 03:56 PM yeah it didn't really do anything :(
sushestvo 08-30-2006, 03: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, 04: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, 05:49 PM preg_replace_callback('/\[no\].*?\].*?\[\/no\]/is', create_function('$matches', 'return str_replace($search, $replace, $matches[0]);'), $string);
sushestvo 08-30-2006, 08:14 PM have another function worked. With preg_replace_callback.
Thanks all =)
|
|