PHP to replace the white space, line break, Chinese comma, and so on with the regular expression of the English comma _php tips

Source: Internet
Author: User
Tags explode

In the development process, you will often encounter the need to give someone an input box, and then someone input some ID, or keywords, such as WordPress's background of the label input box:

This is just to judge the English state of the comma, if someone accidentally entered the Chinese state of the comma how to do? What about the decimal point?

So I wrote an expression with a regular, and replaced it with a comma with a blank line break.

Replace the submitted ID with a white space line break with a comma, and then use the Explode function to toggle the array.

Copy Code code as follows:

$ids =$_post["ID"];
$id = preg_replace ("/\ n) | ( \s) | (t) | (\')| (')| (,)/", ', ', $ids);
$topicids = Explode (",", $tids);

This is the addition of a decimal point filter.

Copy Code code as follows:

$ids = preg_replace ("/\ n) | ( \s) | (t) | (\')| (')| (,) | (\.) /", ', ', $ids);

OK, after this treatment, there will be no problem.

Hint: In fact, small knitting feel with JS before submitting to deal with this problem, is a better choice.

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.