Which function of PHP can remove all characters on both sides of the text? (All)

Source: Internet
Author: User
Tags character classes
Trim removes spaces or other predefined characters on both sides of a string. If you specify 2nd parameters (the symbols to be removed), can multiple parameters be removed? But now I'm not sure what kind of symbol will be entered, such as Question Mark, point, pause, and exclamation point. it's impossible to repeat all the symbols? So... trim removes spaces or other pre-defined characters on both sides of the string.
If you specify 2nd parameters (the symbols to be removed), can multiple parameters be removed?
But now I'm not sure what kind of symbol will be entered, such as Question Mark, point, pause, and exclamation point. it's impossible to repeat all the symbols?
So what functions can be used to process all the symbols on both sides of a string?

Reply content:

Trim removes spaces or other predefined characters on both sides of a string.
If you specify 2nd parameters (the symbols to be removed), can multiple parameters be removed?
But now I'm not sure what kind of symbol will be entered, such as Question Mark, point, pause, and exclamation point. it's impossible to repeat all the symbols?
So what functions can be used to process all the symbols on both sides of a string?

You can use preg_replace to replace unnecessary characters with null characters.

Echo preg_replace ('/[! : @ #]/', '',' @ Thi: s! Test # '); ### output this test

This is not just the beginning and end, but all locations will be deleted. if necessary, you need to change the regular expression.

Can I use a regular expression to match the first and last characters and parameterize the matching content and number of times?

1. regular expression matching processing 2. do not use these characters when generating this string

Using regular expressions is the best method,wIt can match all the character classes to exclude special characters.

You can use another method to restrict the Input type to only numbers, letters, and underscores.


  

Since you are not sure about user input, what do you need to delete. So you are sure you want to confirm the things, so do not use the blacklist, consider the whitelist is relatively simple.

If you want anything, you can only enter anything. The rest will not pass ~

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.