Skip to content

Instantly share code, notes, and snippets.

@k-gun

k-gun/get_attrs.php

Last active Dec 19, 2015
Embed
What would you like to do?
<?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
You can’t perform that action at this time.