Reputation: 79
I want to know how to replace whitespaces from a String.
Example String: INFO [06:57:18 INFO]: 03.06 07:05:32 Auto-saving 03.06 07:05:32 [Console] INFO CONSOLE: Enabled level saving 03.06 07:05:32 [Console] INFO CONSOLE
I want to make it: INFO [06:57:18 INFO]: 03.06 07:05:32 Auto-saving 03.06 07:05:32 [Console] INFO CONSOLE: Enabled level saving 03.06 07:05:32 [Console] INFO CONSOLE
I tried the following methods which didn't work for me:
preg_replace('/\s+/', '', $foo);
trim($foo);
I tried to print it as json to see what is really going on and got this output: http://pastebin.com/QY8uGt4V (the output is pretty big)
Upvotes: 0
Views: 64
Reputation: 10067
What you want to do is replace multiple spaces with one? if So you just need to set a space character as the replacement, like this:
preg_replace('/\s+/', ' ', $foo);
trim($foo);
Upvotes: 0
Reputation: 11984
Try this
$str = 'INFO [06:57:18 INFO]: 03.06 07:05:32 Auto-saving 03.06 07:05:32 [Console] INFO CONSOLE: Enabled level saving 03.06 07:05:32 [Console] INFO CONSOLE;';
$output = preg_replace('!\s+!', ' ', $str);
echo $output;
Upvotes: 0