Javascript-post and display of special character handling

Source: Internet
Author: User
<->数据" />
   

Display results such as:

OK, here's the question, when I enter a general character in the input box, the save to database and the final fetch are removed in input to show no problem.

When the input example "< > this special character, although in the process of PHP acquisition and removal of \ and go to \, but eventually these characters are still to be displayed in input, it will cause the HTML format confusion.

What I do now is to replace the English ' and ' with Chinese ' and ', and then replace it with an escape character when the post is received, such as:

<        <   小于号或显示标记>        >   大于号或显示标记&   &   可用于显示其它特殊字符"  "   引号

But always not the best way to ask:

1. What is the best way to handle this?

2. What do you do with an editor such as Kingeditor and FCK?

.

Reply content:

<->数据" />
   

Display results such as:

OK, here's the question, when I enter a general character in the input box, the save to database and the final fetch are removed in input to show no problem.

When the input example "< > this special character, although in the process of PHP acquisition and removal of \ and go to \, but eventually these characters are still to be displayed in input, it will cause the HTML format confusion.

What I do now is to replace the English ' and ' with Chinese ' and ', and then replace it with an escape character when the post is received, such as:

<        <   小于号或显示标记>        >   大于号或显示标记&   &   可用于显示其它特殊字符"  "   引号

But always not the best way to ask:

1. What is the best way to handle this?

2. What do you do with an editor such as Kingeditor and FCK?

.

Escape at output
htmlspecialchars()

Obviously, you shouldn't be escaping like this.

You should turn the double quotes into " this kind of character.

To knot your own stickers:
1.sql before writing with Addslashes () to the special character multibyte slash
2.sql after removal with tripslashes () to the special character de-slash
3. Use Htmspecialchars () to turn special characters into HTML escape characters when outputting html

  • 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.