Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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