Skip to content

Instantly share code, notes, and snippets.

@illucent
Created March 3, 2014 16:58
Show Gist options
  • Select an option

  • Save illucent/9329392 to your computer and use it in GitHub Desktop.

Select an option

Save illucent/9329392 to your computer and use it in GitHub Desktop.
regex php for comma
// loop through posts, populating $departments arrays
foreach($posts as $post) {
$deps = strip_tags( get_post_meta( $post->ID, '_cmb_department_text', TRUE ));
preg_match_all("/,\s*/", $deps, $matches );
$result = array_combine($matches[1], $matches[2]);
$departments[$result][] = $post;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment