Home  >  Article  >  Backend Development  >  PHP implements the replacement of multiple strings into the same code

PHP implements the replacement of multiple strings into the same code

WBOY
WBOYOriginal
2016-07-25 08:58:39968browse
  1. $name = 'Today 3? , very/ cold';
  2. $name = strtolower($name);
  3. //$name = preg_replace('/[^a-z0-9s ]/','',$name);
  4. $name = preg_replace('/[.s+?,/"]/','_',$name); //change spaces
  5. echo $name;
  6. ?> ;
Copy code

where:

$name = preg_replace('/[.s+?,/"]/','_',$name); //change spaces

.s+?,/" is a regular expression, indicating search. The empty symbol ? / " these five characters Others can be added by yourself. If you don’t understand something, you can refer to the content about regular expressions.



Statement:
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