Skip to content

Instantly share code, notes, and snippets.

@SleeplessByte
Created January 30, 2013 16:22
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save SleeplessByte/4674393 to your computer and use it in GitHub Desktop.
Save SleeplessByte/4674393 to your computer and use it in GitHub Desktop.
Reads out attributes foo="bar" octocat as two elements (foo => bar and octocat => )
<?php
function regex_attributes( &$element ) {
$matches = array();
$pattern = '/\s*(?P<key>[^\s=\'"]+)(?:=(?:([\'"])(?P<value>[^\'"]+)[\'"])|\s|$)\s*/sm';
if ( !preg_match_all( $pattern, $element->attributes_raw, $matches, PREG_OFFSET_CAPTURE ) )
return;
foreach ( $matches[0] as $key => $match )
$element->attributes[ $matches['key'][$key][0] ] = $matches['value'][$key][0];
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment