Home  >  Article  >  Backend Development  >  PHP removes excess spaces and keeps only one of multiple consecutive spaces

PHP removes excess spaces and keeps only one of multiple consecutive spaces

WBOY
WBOYOriginal
2016-07-25 08:46:091857browse
  1. /**
  2. * Only one of multiple consecutive spaces is reserved
  3. *
  4. * @param string $string The string to be converted
  5. * @return unknown
  6. */
  7. static public function merge_spaces ( $string )
  8. {
  9. return preg_replace ( "/s(?=s)/","\1", $string );
  10. }
Copy code

Multiple, PHP


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