Skip to content

Instantly share code, notes, and snippets.

@pweinzettel
Created August 4, 2020 17:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pweinzettel/0a2931e32a497f153701dd7d0d87ab1e to your computer and use it in GitHub Desktop.
Save pweinzettel/0a2931e32a497f153701dd7d0d87ab1e to your computer and use it in GitHub Desktop.
List all free fontawesome icons
<?php
function proc_fa($page) {
$curl = curl_init($page);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
$tmp = curl_exec($curl);
curl_close($curl);
preg_match('/window.__inline_data__ =(.*?)<\/script>/s', $tmp, $match);
$res = json_decode($match[1]);
$prepend = ",'";
$append = "'";
foreach ($res[1] as $rex) {
foreach ($rex as $key => $value) {
if (!isset($value->attributes)) { continue; }
foreach ($value->attributes->membership->free as $member) {
$ico = (isset($prepend)?$prepend:'');
switch ($member) {
case 'brands':
$ico .= "fab fa-";
break;
case 'solid':
$ico .= "fas fa-";
break;
case 'regular':
$ico .= "far fa-";
break;
default:
echo ">> ERR-001: ".$member.PHP_EOL;
die();
}
$ico .= $value->attributes->id."'".PHP_EOL;
echo $ico;
}
}
}
}
$url = 'https://fontawesome.com/cheatsheet/free/';
proc_fa($url);
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment