CopyPastor

Detecting plagiarism made easy.

Score: -1; Reported for: Open both answers

Possible Plagiarism

Plagiarized on 2017-02-05
by Faisal

Original Post

Original - Posted on 2013-03-07
by trante



            
Present in both answers; Present only in the new answer; Present only in the old answer;

Sometimes you would need to delete consecutive white spaces. You can do it like this:
$str = "My name is faisal"; $str = preg_replace('/\s\s+/', ' ', $str);
Output:
My name is faisal
**N.B:** [str_replace][1] is better than [preg_replace][2] if you really just want to remove the space character. The reason to use [preg_replace][2] would be to remove all whitespace (including tabs, newlines, etc.)

[1]: http://php.net/manual/en/function.str-replace.php [2]: http://php.net/manual/en/function.preg-replace.php
Sometimes you would need to delete consecutive white spaces. You can do it like this:
$str = "My name is"; $str = preg_replace('/\s\s+/', ' ', $str);
Output:
My name is

        
Present in both answers; Present only in the new answer; Present only in the old answer;