-6

lets say: "    i have       something       here, please allow      me!    "

will become: "i have something here, please allow me!"

1 Answers1

0

Just use preg_replace (select all spaces (which comes more than one in a row) and replace it with a single space).

Example:

<?php
$str = "    i have       something       here, please allow      me!    ";
echo trim(preg_replace('/\s{2,}/', ' ', $str));
Neodan
  • 5,154
  • 2
  • 27
  • 38