-6

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

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

1
  • 1
    Try look up preg_replace(). Oct 10, 2017 at 6:20

1 Answer 1

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));

Not the answer you're looking for? Browse other questions tagged or ask your own question.