Skip to content

Instantly share code, notes, and snippets.

@marceux
Created September 19, 2014 05:16
Show Gist options
  • Save marceux/def4087b41ae518d4927 to your computer and use it in GitHub Desktop.
Save marceux/def4087b41ae518d4927 to your computer and use it in GitHub Desktop.
gfyCat gfyName Grabber
<?php
/**
* Function for grabbing the gfyName from a gfyCat link...
*/
function grabGfyName ($url) {
$pattern = '/((https?:)?\/\/)?(.+?\.)?gfycat\.com\/(.+)/';
$matches = array();
preg_match ($pattern, $url, $matches);
return $matches[4];
}
$gfyUrls = array(
'http://www.gfycat.com/AngryHatefulAsianconstablebutterfly',
'http://gfycat.com/AngryHatefulAsianconstablebutterfly',
'https://fast.gfycat.com/AngryHatefulAsianconstablebutterfly',
'https://gfycat.com/AngryHatefulAsianconstablebutterfly',
'http://demo.gfycat.com/AngryHatefulAsianconstablebutterfly',
'https://center2.gfycat.com/AngryHatefulAsianconstablebutterfly '
);
foreach ($gfyUrls as $url) {
echo grabGfyName($url) . "\n";
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment