Last active
December 31, 2015 14:49
-
-
Save NaWer/8002846 to your computer and use it in GitHub Desktop.
Get the Value of Attributes in HTML tags using PHP
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
<?php | |
/* | |
* Return the value of an attribute in HTML tag | |
*/ | |
function getAttribute($attrib, $tag) | |
{ | |
$re = '/' . preg_quote($attrib) . '=([\'"])?((?(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