Skip to content

Instantly share code, notes, and snippets.

@krmgns
Last active December 19, 2015 09:58
Show Gist options
  • Save krmgns/5936462 to your computer and use it in GitHub Desktop.
Save krmgns/5936462 to your computer and use it in GitHub Desktop.
<?php
$html = '<img class="medium" src="/images/image.jpg" width="100" height="75">';
// get attrs
preg_match_all('~([\w]+?)="(.*?)"~i', $html, $m);
$attrs = array_combine($m[1], $m[2]);
print_r($attrs);
// result
/*
Array
(
[class] => medium
[src] => /images/image.jpg
[width] => 100
[height] => 75
)
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment