Skip to content

Instantly share code, notes, and snippets.

@mdamien
Created September 25, 2013 14:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mdamien/6700684 to your computer and use it in GitHub Desktop.
Save mdamien/6700684 to your computer and use it in GitHub Desktop.
Parse a wordpress shortcode into a PHP array
function get_atts_from_shortcode_with_a_good_old_regex($content) {
$regexp = '/(.?)\[(shop)\b(.*?)(?:(\/))?\](?:(.+?)\[\/\2\])?(.?)/s';
$m = array();
preg_match($regexp, $content, $m);
$arr = array('content' => $m[5]);
$arr = array_merge(shortcode_parse_atts($m[3]),$arr);
return $arr;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment