PHP Convert text box content to HTML format _php tips

Source: Internet
Author: User
Tags php programming php regular expression

This article is an example of how PHP transforms text box content into HTML format. Share to everyone for your reference, specific as follows:

Sometimes we're going to use the HTML format for the content that you enter in a multiline text box to keep the original text formatting, such as wrapping, carriage return, and so on. You can do this by using the following function:

function shtm ($design _str)
{
 $str =trim ($design _str);//get string at the same time to turn tail space and empty carriage return
 //$str =str_replace ("<br > "," ", $str); Remove <br> label
 //$str = "<p>". Trim ($STR);//Add <p>
 $str =str_replace ("\ r \ n", "<br>") to the text header $STR); Replace line breaks
 //$STR with P tags. = "</p>\n";//Text tail add </p>
 $str =str_replace ("<p></p>", "", $str); /Remove empty paragraphs
 $str =str_replace ("\ n", "", $str);//Remove blank lines and line
 $str =str_replace ("</p>", "</p>\n", $str); /Organize HTML code return
 $str;
}

PS: This site also provides the following conversion tools for everyone to choose to use:

Online HTML/JS/CSS Code filtering tool:
Http://tools.jb51.net/code/htmlfilter

Online ubb/html Code conversion tool:
Http://tools.jb51.net/transcoding/ubb2html

HTML conversion to other language output tools:
Http://tools.jb51.net/code/HtmlCodeCov

For more information about PHP interested readers can view the site topics: "PHP coding and transcoding Operation tips Summary", "PHP object-oriented Programming Introduction Course", "PHP Mathematical Calculation Skills Summary", "PHP Array" Operation Techniques Encyclopedia, "PHP string (String) Usage summary, "PHP Data structure and algorithm tutorial", "PHP Programming Algorithm Summary", "PHP Regular Expression Usage Summary", and "PHP common database Operation skill Summary"

I hope this article will help you with the PHP program design.

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.