Skip to content

Instantly share code, notes, and snippets.

@martinsanne
Created December 9, 2015 09:41
Show Gist options
  • Save martinsanne/92d1434b6b2fc73aca74 to your computer and use it in GitHub Desktop.
Save martinsanne/92d1434b6b2fc73aca74 to your computer and use it in GitHub Desktop.
Parse url attributes
$subject = '<a href="#" data-type="page" data-value="1" data-title="Dickbutt"></a>';
preg_match_all(
'/<a
(?:\s+
(?:
href=["\'](?P<href>[^"\'<>]+)["\']
|
data-value=["\'](?P<value>[^"\'<>]+)["\']
|
data-title=["\'](?P<title>[^"\'<>]+)["\']
|
data-type=["\'](?P<type>[^"\'<>]+)["\']
|
\w+=["\'][^"\'<>]+["\']
)
)+/ix',
$subject, $result, PREG_PATTERN_ORDER);
echo '<pre style="text-align:left;">';
print_r($result);
echo '</pre>';
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment