Title: shortcode_parse_atts() and PHP Versions
Last modified: August 20, 2016

---

# shortcode_parse_atts() and PHP Versions

 *  [toneburst](https://wordpress.org/support/users/toneburst/)
 * (@toneburst)
 * [13 years, 3 months ago](https://wordpress.org/support/topic/shortcode_parse_atts-and-php-versions-1/)
 * I’m trying to parse a shortcode string in a custom ‘shortcode helper’ TinyMCE
   editor popup.
 * Rather than write my own function from scratch, I thought I’d use the existing
   WordPress shortcode-parser, ‘shortcode_parse_atts()’ in wp-includes/shortcodes.
   php. I’m getting odd results though.
 * I’m currently testing the site offline, using MAMP, which gives me the option
   to change the PHP version between 5.2.17 and 5.4.4 (I don’t know why just those
   particular versions).
 * In PHP v.5.4.4, everything appears to work fine. The function returns an associative
   array of key=>value pairs from the shortcode string, as expected.
 * However, in the older PHP version, shortcode_parse_atts() returns each shortcode
   attribute key/value pair as a single string, in an unkeyed array, which breaks
   the rest of my code.
 * Anyone know why this is happening? Other shortcodes appear work as they should
   otherwise, in both PHP versions, so I’m stumped why the same function that is(
   I presume) used by WordPress itself doesn’t work in the context of my popup panel.
 * Anyone any idea why this might be happening, and how I might go about fixing 
   it?
 * For reference, here is the function in question:
 *     ```
       function shortcode_parse_atts($text) {
       	$atts = array();
       	$pattern = '/(\w+)\s*=\s*"([^"]*)"(?:\s|$)|(\w+)\s*=\s*\'([^\']*)\'(?:\s|$)|(\w+)\s*=\s*([^\s\'"]+)(?:\s|$)|"([^"]*)"(?:\s|$)|(\S+)(?:\s|$)/';
       	$text = preg_replace("/[\x{00a0}\x{200b}]+/u", " ", $text);
       	if ( preg_match_all($pattern, $text, $match, PREG_SET_ORDER) ) {
       		foreach ($match as $m) {
       			if (!empty($m[1]))
       				$atts[strtolower($m[1])] = stripcslashes($m[2]);
       			elseif (!empty($m[3]))
       				$atts[strtolower($m[3])] = stripcslashes($m[4]);
       			elseif (!empty($m[5]))
       				$atts[strtolower($m[5])] = stripcslashes($m[6]);
       			elseif (isset($m[7]) and strlen($m[7]))
       				$atts[] = stripcslashes($m[7]);
       			elseif (isset($m[8]))
       				$atts[] = stripcslashes($m[8]);
       		}
       	} else {
       		$atts = ltrim($text);
       	}
       	return $atts;
       }
       ```
   
 * Cheers,
 * a|x

Viewing 3 replies - 1 through 3 (of 3 total)

 *  [minkowski](https://wordpress.org/support/users/minkowski/)
 * (@minkowski)
 * [13 years, 3 months ago](https://wordpress.org/support/topic/shortcode_parse_atts-and-php-versions-1/#post-3291178)
 * Edited.
 *  Thread Starter [toneburst](https://wordpress.org/support/users/toneburst/)
 * (@toneburst)
 * [13 years, 3 months ago](https://wordpress.org/support/topic/shortcode_parse_atts-and-php-versions-1/#post-3291185)
 * Hi Minkowski,
 * would be interested to know what you said, before you edited it…
 * a|x
 *  Thread Starter [toneburst](https://wordpress.org/support/users/toneburst/)
 * (@toneburst)
 * [13 years, 3 months ago](https://wordpress.org/support/topic/shortcode_parse_atts-and-php-versions-1/#post-3291205)
 * Just discovered it doesn’t seem to work with PHP v.5.3.6, either. Again, odd,
   because shortcodes seem to be parsed fine in the frontend.
 * a|x

Viewing 3 replies - 1 through 3 (of 3 total)

The topic ‘shortcode_parse_atts() and PHP Versions’ is closed to new replies.

## Tags

 * [Parsing](https://wordpress.org/support/topic-tag/parsing/)
 * [php versions](https://wordpress.org/support/topic-tag/php-versions/)
 * [shortcode](https://wordpress.org/support/topic-tag/shortcode/)

 * In: [Hacks](https://wordpress.org/support/forum/plugins-and-hacks/hacks/)
 * 3 replies
 * 2 participants
 * Last reply from: [toneburst](https://wordpress.org/support/users/toneburst/)
 * Last activity: [13 years, 3 months ago](https://wordpress.org/support/topic/shortcode_parse_atts-and-php-versions-1/#post-3291205)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
