what function does PHP have to remove all characters from both sides of the text? All

Source: Internet
Author: User
Trim is the removal of whitespace characters or other predefined characters on either side of a string.
If you specify a 2nd parameter (the symbol you want to remove), can you remove more than one?
But now it is not sure what kind of symbol will be entered, such as question mark, dot, comma, exclamation mark, it is impossible to all the symbols to play it again?
So what function can I handle all the symbols on both sides of the string?

Reply content:

Trim is the removal of whitespace characters or other predefined characters on either side of a string.
If you specify a 2nd parameter (the symbol you want to remove), can you remove more than one?
But now it is not sure what kind of symbol will be entered, such as question mark, dot, comma, exclamation mark, it is impossible to all the symbols to play it again?
So what function can I handle all the symbols on both sides of the string?

You can use Preg_replace to replace the characters that are not required to be empty.

echo preg_replace('/[!:@#]/', '', '@thi:s! test#');###输出this test

This is not only the end-to-end, all locations will be deleted, if necessary, the need to change the regular.

Can I use regular expressions to match the kinsoku characters and parameterize the matching content and number of times?

1.正则匹配处理2.生成这个字符串的时候就不要这些字符

Using regular is the best way, you can take a good look, w you can match all the characters, thus eliminating the special symbol

You can change your mind. Limit input type only allow input alphanumeric underline


  
   

既然你不确定用户输入,你需要删除哪些东西。那么你确定要的东西肯定是确定的,所以不要使用黑名单制,考虑白名单比较简单。

就是你要啥,就只允许输入啥,其他都不通过~

  • Related Article

    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.