Php ubb code parsing program

Source: Internet
Author: User
The code is as follows: Copy code

/**
+ ----------------------------------------------------------
* UBB parsing
+ ----------------------------------------------------------
* @ Return string
+ ----------------------------------------------------------
*/
Function ubb ($ Text ){
$ Text = trim ($ Text );
$ Text = ereg_replace ("n", "<br>", $ Text );
$ Text = preg_replace ("/\ t/is", "", $ Text );
$ Text = preg_replace ("/[hr]/is", "$ Text = preg_replace ("/[separator]/is", "<br/>", $ Text );
$ Text = preg_replace ("/[h1] (. + ?) [/H1]/is "," $ Text = preg_replace ("/[h2] (. + ?) [/H2]/is "," $ Text = preg_replace ("/[h3] (. + ?) [/H3]/is "," $ Text = preg_replace ("/[h4] (. + ?) [/H4]/is "," $ Text = preg_replace ("/[h5] (. + ?) [/H5]/is "," $ Text = preg_replace ("/[h6] (. + ?) [/H6]/is "," $ Text = preg_replace ("/[center] (. + ?) [/Center]/is "," <center> \ 1 </center> ", $ Text );
// $ Text = preg_replace ("/[url = ([^ [] *)] (. + ?) [/Url]/is "," <a href = \ 1 target = '_ blank'> \ 2 </a> ", $ Text );
$ Text = preg_replace ("/[url] (. + ?) [/Url]/is "," <a href = "\ 1" target = '_ blank'> \ 1 </a> ", $ Text );
$ Text = preg_replace ("/[url = (http: //. ++?)] (. + ?) [/Url]/is "," <a href = '\ 1' target =' _ blank '> \ 2 </a> ", $ Text );
$ Text = preg_replace ("/[url = (. +?)] (. + ?) [/Url]/is "," <a href = \ 1> \ 2 </a> ", $ Text );
$ Text = preg_replace ("/[img] (. + ?) [/Img]/is "," ", $ Text );
$ Text = preg_replace ("/[imgs (. +?)] (. + ?) [/Img]/is "," ", $ Text );
$ Text = preg_replace ("/[color = (. +?)] (. + ?) [/Color]/is "," <font color = \ 1> \ 2 </font> ", $ Text );
$ Text = preg_replace ("/[colorTxt] (. + ?) [/ColorTxt]/eis "," color_txt ('\ 1') ", $ Text );
$ Text = preg_replace ("/[style = (. +?)] (. + ?) [/Style]/is "," <div class = '\ 1'> \ 2 </div> ", $ Text );
$ Text = preg_replace ("/[size = (. +?)] (. + ?) [/Size]/is "," <font size = \ 1> \ 2 </font> ", $ Text );
$ Text = preg_replace ("/[sup] (. + ?) [/Sup]/is "," <sup> \ 1 </sup> ", $ Text );
$ Text = preg_replace ("/[sub] (. + ?) [/Sub]/is "," <sub> \ 1 </sub> ", $ Text );
$ Text = preg_replace ("/[pre] (. + ?) [/Pre]/is "," <pre> \ 1 </pre> ", $ Text );
$ Text = preg_replace ("/[emot] (. + ?) [/Emot]/eis "," emot ('\ 1') ", $ Text );
$ Text = preg_replace ("/[email] (. + ?) [/Email]/is "," <a href = 'mailto: \ 1'> \ 1 </a> ", $ Text );
$ Text = preg_replace ("/[I] (. + ?) [/I]/is "," <I> \ 1 </I> ", $ Text );
$ Text = preg_replace ("/[u] (. + ?) [/U]/is "," <u> \ 1 </u> ", $ Text );
$ Text = preg_replace ("/[B] (. + ?) [/B]/is "," <B> \ 1 </B> ", $ Text );
$ Text = preg_replace ("/[quote] (. + ?) [/Quote]/is "," <blockquote> Reference: <div style = 'border: 1px solid silver; background: # EFFFDF; color: #393939; padding: 5px '> \ 1 </div> </blockquote> ", $ Text );
$ Text = preg_replace ("/[code] (. + ?) [/Code]/eis "," highlight_code ('\ 1') ", $ Text );
$ Text = preg_replace ("/[php] (. + ?) [/Php]/eis "," highlight_code ('\ 1') ", $ Text );
$ Text = preg_replace ("/[sig] (. + ?) [/Sig]/is "," <div style = 'text-align: left; color: darkgreen; margin-left: 5% '> <br> ------------------------ <br> \ 1 <br> -------------------------- </div> ", $ Text );
Return $ Text;
}

Preg_replace () function syntax

Preg_replace function basics and instance code
// Preg_replace (mixed $ pattern, mixed $ replacement, mixed $ subject [, int $ limit =-1 [, int & $ count]) subject: match search mode, replace
/*
The pattern to be searched. It can be a string or a string array.

After the electronic modifier causes the preg_replace function () to replace the treatment, the appropriate reference as a parameter is replaced by the php Tutorial code. Tip: Make sure that the replacement constitutes a valid php code string. Otherwise, php will complain about parsing errors including the preg_replace function line.

Return value

The preg_replace function () returns an array. If the parameter in this issue is an array or a string, otherwise.

If a match is found, a new problem will occur. Otherwise, the returned topic will remain unchanged or null if an error occurs.


For more details, see: http://www.111cn.net/phper/php-function/33530.htm

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.