Created
February 25, 2013 23:41
-
-
Save greylabel/5034403 to your computer and use it in GitHub Desktop.
regex to get html tag attribute value
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
<?php | |
/** | |
* regex to get html tag attribute value | |
*/ | |
function get_attribute_value($attrib, $tag){ | |
//get attribute from html 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