How to strip (clear, remove) all spaces from a string in PHP

2 Answers

0 votes
$s = "php           java  python c#";

$s = str_replace(' ', '', $s);

echo $s;

  
/*
run:
   
phpjavapythonc# 
   
*/

 



answered Oct 10, 2017 by avibootz
0 votes
$s = "php           java  python c#";

$s = preg_replace('/\s+/', '', $s);

echo $s;

  
/*
run:
   
phpjavapythonc# 
   
*/

 



answered Oct 10, 2017 by avibootz
...