PHP Filter English punctuation and filter Chinese punctuation code _php Tips

Source: Internet
Author: User
Tags learn php trim urlencode

PHP filter English punctuation marks to filter Chinese punctuation code

Copy Code code as follows:

function Filter_mark ($text) {
if (Trim ($text) = = ') return ';
$text =preg_replace ("/[[:p unct:]\s]/", "", $text);
$text =urlencode ($text);
$text =preg_replace ("/(%7e|%60|%21|%40|%23|%24|%25|%5e|%26|%27|%2a|%28|%29|%2b|%7c|%5c|%3d|\-|_|%5b|%5d|%7d|%7b |%3b|%22|%3a|%3f|%3e|%3c|%2c|\.| %2f|%a3%bf|%a1%b7|%a1%b6|%a1%a2|%a1%a3|%a3%ac|%7d|%a1%b0|%a3%ba|%a3%bb|%a1%ae|%a1%af|%a1%b1|%a3%fc|%a3%bd|%a1% aa|%a3%a9|%a3%a8|%a1%ad|%a3%a4|%a1%a4|%a3%a1|%e3%80%82|%ef%bc%81|%ef%bc%8c|%ef%bc%9b|%ef%bc%9f|%ef%bc%9a|%e3% 80%81|%e2%80%a6%e2%80%a6|%e2%80%9d|%e2%80%9c|%e2%80%98|%e2%80%99|%ef%bd%9e|%ef%bc%8e|%ef%bc%88) +/", ', $text);
$text =urldecode ($text);
Return trim ($text);
}

We do data acquisition or verification process, often need to do some special data processing, such as the removal of Chinese and English punctuation, reference to the online method, the more reliable PHP removal in English and Chinese code as follows:

<?php
$keyword = "good". , Good learning php!!! ";
$keyword =urlencode ($keyword);//The keyword is encoded
$keyword =preg_replace ("/(%7e|%60|%21|%40|%23|%24|%25|%5e|%26|%27|%2a |%28|%29|%2b|%7c|%5c|%3d|\-|_|%5b|%5d|%7d|%7b|%3b|%22|%3a|%3f|%3e|%3c|%2c|\.| %2f|%a3%bf|%a1%b7|%a1%b6|%a1%a2|%a1%a3|%a3%ac|%7d|%a1%b0|%a3%ba|%a3%bb|%a1%ae|%a1%af|%a1%b1|%a3%fc|%a3%bd|%a1% aa|%a3%a9|%a3%a8|%a1%ad|%a3%a4|%a1%a4|%a3%a1|%e3%80%82|%ef%bc%81|%ef%bc%8c|%ef%bc%9b|%ef%bc%9f|%ef%bc%9a|%e3% 80%81|%e2%80%a6%e2%80%a6|%e2%80%9d|%e2%80%9c|%e2%80%98|%e2%80%99) +/", ', $keyword);
$keyword =urldecode ($keyword);//to decode the filtered keyword
echo $keyword;

Output results:

Learn PHP Well

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.