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.
$str = 'hola hola "pepsi cola" yay'; preg_match_all('/[^\s"]+|"[^"]*"/', $str, $matches); echo implode('', $matches[0]); // holahola"pepsi cola"yay
Comments
Post a Comment