php - Explode string with '/' and escape if it contains space around '/', like ' / ' -
how possible explode string using '/', if slash doesn't contain spaces before or after. i wish string "flat visors / fitted caps" treated string , "flat visors/fitted caps" explode using '/'. you can use preg_split negative look-behind , negative look-ahead: preg_split('/(?<!\s)\\/(?!\s)/', $str); if wish opposite, i.e. splitting when there space around , remove space, again preg_split , optional space: preg_split('/\s*\\/\s*/', $str);