Created
October 18, 2009 13:12
-
-
Save amphibian/212675 to your computer and use it in GitHub Desktop.
PHP function to return any given attribute of a complete HTML tag.
This file contains 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
/* | |
This function will return any given attribute of a complete HTML tag. | |
Originally found at http://www.phpfreaks.com/forums/index.php?topic=209684.0 | |
*/ | |
function getAttribute($attribute, $tag) | |
{ | |
$re = '/' . preg_quote($attribute) . '=([\'"])?((?(1).+?|[^\s>]+))(?(1)\1)/is'; | |
if( preg_match($re, $tag, $match) ) | |
{ | |
return urldecode($match[2]); | |
} | |
return false; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment