This article describes how to replace spaces, line breaks, Chinese commas, and so on with regular expressions of English commas. For more information, see
This article describes how to replace spaces, line breaks, Chinese commas, and so on with regular expressions of English commas. For more information, see
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 English. What if someone accidentally enters a comma in Chinese? 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.