PHP regular expression to replace spaces, newlines, Chinese commas, etc. with English commas_PHP Tutorial

WBOY
Release: 2016-07-13 10:30:48
Original
817 people have browsed it

During the development process, we often encounter the need to provide an input box for others, and then others enter some IDs or keywords, such as the tag input box in the WordPress background:

PHP regular expression to replace spaces, newlines, Chinese commas, etc. with English commas_PHP Tutorial

This is just to determine the comma in the English state. What if someone accidentally enters a comma in the Chinese state? What to do with the decimal point?

So I wrote an expression using regular expressions to replace spaces and line breaks with commas.

Replace the submitted ID with spaces, line breaks, etc. into commas, and then use the explode function to switch to an array.

Copy code The code is as follows:

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

This is filtering with a decimal point added.

Copy code The code is as follows:

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

OK, after processing like this, there will be no problem.

Tip: In fact, the editor feels that using JS to handle this problem before submission is a better choice.

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/764620.htmlTechArticleDuring the development process, we often encounter the need to provide an input box for others, and then others enter some IDs. Or keywords, such as the tag input box in the WordPress backend: This...
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template