Skip to content

Instantly share code, notes, and snippets.

@anytizer
Created November 25, 2013 09:12
Show Gist options
  • Save anytizer/7638630 to your computer and use it in GitHub Desktop.
Save anytizer/7638630 to your computer and use it in GitHub Desktop.
Extract src and href
<?php
$path = '/home/USER/public_html';
function resources($path)
{
$resources = array(
'file' => $path,
'href' => array(),
'src' => array(),
'success' => false,
);
$fc = file_get_contents($path);
$hrefs = array();
preg_match_all('/href="(.*?)"/is', $fc, $hrefs);
$resources['href'] = $hrefs[1];
$srcs = array();
preg_match_all('/src="(.*?)"/is', $fc, $srcs);
$resources['src'] = $srcs[1];
$resources['success'] = (count($resources['src']) || count($resources['href']));
return $resources;
}
chdir($path);
$files = glob('*.php');
foreach($files as $f => $file)
{
$resources = resources($file);
if($resources['success'])
{
print_r($resources);
}
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment