Created
December 9, 2015 09:41
-
-
Save martinsanne/92d1434b6b2fc73aca74 to your computer and use it in GitHub Desktop.
Parse url attributes
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$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