php remove space inside string

You can remove space any where in string using regex preg_replace.preg_replace is function which work on regex to search and replace in string.Regular express is strong part of php.You can also search replace html tags.Here I have used regex string feature to search and replace space.

Here is example how you can remove space anywhere in php

   $str = 'nik                  unj';
   $str = preg_replace('/\s\s+/', '', $str);
   echo $str;

Will Return