Php method to convert ubb code _ PHP

Source: Internet
Author: User
Tags php regular expression
This article mainly introduces how php implements ubb code conversion and involves the use of php regular expression replacement. if you need it, refer to the example in this article to illustrate how php implements ubb code conversion. Share it with you for your reference. The details are as follows:

Function ubb2html ($ content) {global $ article; // whether to automatically recognize if ($ article ['isparseurl'] = "1 ") {$ content = parseurl ($ content);} // automatically identifies end $ content = eregi_replace (quotemeta ("[B]"), quotemeta (""), $ Content); $ content = eregi_replace (quotemeta (" [/B] "), quotemeta (""), $ Content); $ content = eregi_replace (quotemeta (" [I] "), quotemeta (""), $ Content); $ content = eregi_replace (quotemeta (" [/I] "), quotemeta (""), $ Content); $ content = eregi_replace (quotemeta (" [u] "), quotemeta (""), $ Content); $ content = eregi_replace (quotemeta (" [/u] "), quotemeta (""), $ Content); $ content = eregi_replace (quotemeta (" [center] "), quotemeta ("
 
  
"), $ Content); $ content = eregi_replace (quotemeta (" [/center] "), quotemeta ("
 "), $ Content); $ content = eregi_replace (quotemeta (" [quote] "), quotemeta ("
 
 
Reference:
"), $ Content); $ content = eregi_replace (quotemeta (" [/quote] "), quotemeta ("
"), $ Content); $ content = eregi_replace (quotemeta ("

The code is as follows:

"), Quotemeta ("

Code:
"), $ Content); $ content = eregi_replace (quotemeta ("

"), Quotemeta ("
"), $ Content); $ content = eregi_replace (" \ [images \] ([^ \ [] *) \ [/images \] ", "screen. width-333) this. width = screen. width-333 \ "title = \" use a new window to browse the original image \ ">", $ content); $ content = eregi_replace ("\ [url \] www. ([^ \ [] *) \ [/url \] "," www. \ 1 ", $ content); $ content = eregi_replace (" \ [url \] ([^ \ [] *) \ [/url \] "," \ 1 ", $ content); $ content = eregi_replace (" \ [url = ([^ \ [] *) \] ([^ \ [] *) \ [/url \] "," \ 2 ", $ content ); $ content = eregi_replace ("\ [email \] ([^ \ [] *) \ [/email \]", "\ 1 ", $ content); // $ content = preg_replace ('/javascript/I', 'Java script', $ content); return $ content ;}

I hope this article will help you with php programming.

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.