Split string by commas and spaces but preserve quoted strings

/ Published in: Regular Expression
Save to your folder(s)

will split the string
"I am" search words

[0] => I am
[1] => searching
[2] => words

Copy this code and paste it in your HTML
  1. $split_tags = preg_split( "/[\s,]*\\\"([^\\\"]+)\\\"[\s,]*|[\s,]+/", $search_term, 0, PREG_SPLIT_DELIM_CAPTURE|PREG_SPLIT_NO_EMPTY );

Report this snippet


RSS Icon Subscribe to comments

You need to login to post a comment.