Skip to content

Instantly share code, notes, and snippets.

@NaWer
Last active December 31, 2015 14:49
Show Gist options
  • Save NaWer/8002846 to your computer and use it in GitHub Desktop.
Save NaWer/8002846 to your computer and use it in GitHub Desktop.
Get the Value of Attributes in HTML tags using PHP
<?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