fork download
  1. <?php
  2.  
  3. $str = ' But I must explain to you how all this mistaken';
  4. echo preg_replace('/(?= )\s+|(\w).*/u', '$1', $str);
Success #stdin #stdout 0.02s 24472KB
stdin
Standard input is empty
stdout
B