conware
07-26-2012, 09:41 AM
Hi guys I wanted to make a function to remove certain bbcode from my user comments only problem is I don't know much regex code.
<?php
function stripBBCode($text, $code, $replace = '') {
$pattern = "/\[?.($code)\]/";
return preg_replace($pattern, $replace, $text);
}
$text = "google (http://google.com) is fine http://www.google.com/image/image.jpg";
echo stripBBCode($text, '(url||img)');
?>
The basic idea is to supply the bbcode I want to remove to my function.
And then use regex and preg_replace to clean the text.
Now the idea is to keep the text between the bbcode so users can still for example go or see the image if the really wanted to.
So for example if I have this text:
google (http://google.com) is fine http://www.google.com/image/image.jpg
And I run the code I want it to become:
google is fine http://www.google.com/image/image.jpg
<?php
function stripBBCode($text, $code, $replace = '') {
$pattern = "/\[?.($code)\]/";
return preg_replace($pattern, $replace, $text);
}
$text = "google (http://google.com) is fine http://www.google.com/image/image.jpg";
echo stripBBCode($text, '(url||img)');
?>
The basic idea is to supply the bbcode I want to remove to my function.
And then use regex and preg_replace to clean the text.
Now the idea is to keep the text between the bbcode so users can still for example go or see the image if the really wanted to.
So for example if I have this text:
google (http://google.com) is fine http://www.google.com/image/image.jpg
And I run the code I want it to become:
google is fine http://www.google.com/image/image.jpg