This article mainly introduces the php class for filtering UBB code and involves the php regular expression operation skills. it has some reference value, for more information about how to filter UBB code in php, see the following example. Share it with you for your reference. The details are as follows:
The PHP code is as follows:
The code is as follows:
Class Day {
Function ubb ($ Text) {// UBB code conversion
// $ Text = htmlspecialchars ($ Text );
// $ Text = ereg_replace ("\ r \ n ","
", $ Text );
$ Text = ereg_replace ("\ [br \]","
", $ Text );
$ Text = nl2br ($ Text );
$ Text = stripslashes ($ Text );
$ Text = preg_replace ("// \ t/is", "", $ Text );
$ Text = preg_replace ("/\ [url \] (http: \/. + ?) \ [\/Url \]/is ","\ 1", $ Text );
$ Text = preg_replace ("/\ [url \] (. + ?) \ [\/Url \]/is ","\ 1", $ Text );
$ Text = preg_replace ("/\ [url = (http: \/. + ?) \] (. + ?) \ [\/Url \]/is ","\ 2", $ Text );
$ Text = preg_replace ("/\ [url = (. + ?) \] (. + ?) \ [\/Url \]/is ","\ 2", $ Text );
$ Text = preg_replace ("/\ [color = (. + ?) \] (. + ?) \ [\/Color \]/is "," \ 2 ", $ Text );
$ Text = preg_replace ("/\ [font = (. + ?) \] (. + ?) \ [\/Font \]/is "," \ 2 ", $ Text );
$ Text = preg_replace ("/\ [email = (. + ?) \] (. + ?) \ [\/Email \]/is ","\ 2", $ Text );
$ Text = preg_replace ("/\ [email \] (. + ?) \ [\/Email \]/is ","\ 1", $ Text );
$ Text = preg_replace ("/\ [I \] (. + ?) \ [\/I \]/is ","\ 1", $ Text );
$ Text = preg_replace ("/\ [u \] (. + ?) \ [\/U \]/is ","\ 1", $ Text );
$ Text = preg_replace ("/\ [B \] (. + ?) \ [\/B \]/is ","\ 1", $ Text );
$ Text = preg_replace ("/\ [fly \] (. + ?) \ [\/Fly \]/is "," \ 1 ", $ Text );
$ Text = preg_replace ("/\ [move \] (. + ?) \ [\/Move \]/is "," \ 1 ", $ Text );
$ Text = preg_replace ("/\ [shadow = ([# 0-9a-z] {1, 10}) \, ([0-9] {1, 3 })\, ([0-9] {1, 2}) \] (. + ?) \ [\/Shadow \]/is ","
", $ Text );
Return $ Text;
}
}
I hope this article will help you with php programming.