regex - Removing whitespace-characters, except inside quotation marks in PHP? -


i need remove whitespace string, quotations should stay were.

here's example:

string parse: hola hola "pepsi cola" yay  output: holahola"pepsi cola"yay 

any idea? i'm sure can done regex, solution okay.

we match strings or quotations with

[^\s"]+|"[^"]*" 

so need preg_match_all , concatenate result.


example:

$str = 'hola hola "pepsi cola" yay';  preg_match_all('/[^\s"]+|"[^"]*"/', $str, $matches);  echo implode('', $matches[0]); // holahola"pepsi cola"yay 

Comments

Popular posts from this blog

c++ - Convert big endian to little endian when reading from a binary file -

C#: Application without a window or taskbar item (background app) that can still use Console.WriteLine() -

unicode - Are email addresses allowed to contain non-alphanumeric characters? -