PHP replaces spaces, line breaks, Chinese commas, and so on with the regular expression of English commas

Source: Internet
Author: User
This article describes how to replace spaces, line breaks, Chinese commas, and other regular expressions with English commas.

In the process of development, you will often encounter a need to provide an input box for others, and then others enter some ID or keyword, such as the wordpress background tag input box:

This is just a comma in the English state. what if someone accidentally enters a comma in the Chinese state? What about decimal point?

So I wrote an expression with a regular expression and replaced the line break with a space with a comma.

Replace the submitted id with a space newline character with a comma, and then use the explode function to switch to an array.
The code is as follows:
$ Ids = $ _ POST ["ID"];
$ Id = preg_replace ("/(\ n) | (\ s) | (\ t) | (\ ') | (,)/",', ', $ ids );
$ Topicids = explode (",", $ tids );

This adds a decimal point filter.
The code is as follows:
$ Ids = preg_replace ("/(\ n) | (\ s) | (\ t) | (\ ') | (,) | (\.) /", ',', $ ids );

OK. after such processing, there will be no problem.

Tip: in fact, it is a better choice for Xiaobian to handle this problem before submitting JavaScript code.

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.