Convert UBB into html code using php

Source: Internet
Author: User
Some people think that UBB is very difficult and do not know how to get started. In fact, it is very simple to replace regular expressions. The following is the code for converting UBB into HTML, which is only a small part. here we just want to make an example, this section describes how to convert UBB into HTML code that can be recognized by the browser. the Function preg_replace is mainly used. I will not introduce it here. For details, refer to the manual. In addition to this function, you can also use str_re. some people think that UBB is very difficult and do not know how to start with it. In fact, it is very simple to replace regular expressions. below is the code for converting some UBB into HTML, which is only a small part, this is just an example to illustrate how to convert UBB into HTML code that can be recognized by the browser, mainly the preg_replace function. I will not introduce it here. Read the manual for details, it is detailed. In addition to this function, you can also use functions such as str_replace.
You can add regular expression replacement to the $ match and $ replace arrays for extension.
Function ubb2html ($ strCodes ){
$ Match = array (
"% \ [B \] (. *?) \ [\/B \] % si ",
"% \ [Center \] (. *?) \ [\/Center \] % si ",
"% \ [Url \] (. *?) \ [\/Url \] % si ",
"% \ [Url = (.*?) \] (. *?) \ [\/Url \] % si ",
"% \ [Img \] (. *?) \ [\/Img \] % si ",
"% \ [Fieldset = (.*?) \] (. *?) \ [\/Fieldset \] % si"
);
$ Replace = array (
"$1",
" $1 ",
"$1 ",
"$2 ",
"550) this. width = 500 \" title = \ "Click here to browse the image in a new window \"> ",
" $1
$2
"
);
$ StrCodes = preg_replace ($ match, $ replace, $ strCodes );

Return $ strCodes;
}
?>

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.