Skip to content

Instantly share code, notes, and snippets.

@greylabel
Created February 25, 2013 23:41
Show Gist options
  • Save greylabel/5034403 to your computer and use it in GitHub Desktop.
Save greylabel/5034403 to your computer and use it in GitHub Desktop.
regex to get html tag attribute value
<?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