How does the HTML code for user input be handled in web development?

Source: Internet
Author: User
To preserve the HTML code entered by the user, here is the HTML code:

a

b

How it's done.

Sorry, I don't speak clearly enough, I want to say:

A

b

These two lines are user-submitted data, perhaps through the editor, perhaps the user manually input, server-side programs (such as PHP) received the data is the above two lines of characters, I would like to ask is if the browser again display the two lines of code and the DIV and P elements can be parsed by the browser, namely: In the browser is a red character A and a green B, in addition to directly output them to the browser is there any good way? because I'm worried about the output of the user's input data will break the page structure, such as:

<

Div style= "color:red" >

A

Will bring in an unclosed div tag.

Reply content:

To preserve the HTML code entered by the user, here is the HTML code:

a

b

How it's done.

Sorry, I don't speak clearly enough, I want to say:

A

< > escape Several common symbols of code and turn them into HTML entity storage. PHP words have htmlspecialchars functions.

Well, you can use the Code Editor.
Like what:
A

B

That's what I got in the comment box.

a

b

can be converted into

<div style="color:red">a</div><p style="color:green">b</p>

In general, these code symbols are escaped into HTML to store. The general language has the correlation function to implement it.

  • Related Article

    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.