.dev/scripts/fontawesome_icons/get_latest_icons.php

Summary

Maintainability
A
1 hr
Test Coverage
#!/usr/bin/env php
<?php

function data_get_latest_icons()
{
    $url = 'http://fontawesome.io/cheatsheet/';
    $f2 = __DIR__ . '/' . basename($url);
    if (!file_exists($f2)) {
        $html1 = file_get_contents($url);
        $regex1 = '~<h2[^>]*page-header[^>]*>.*?</h2>[^>]*<div class="row">(.*?</div>)[^>]*</div>~ims';
        preg_match($regex1, $html1, $m1);
        file_put_contents($f2, $m1[1]);
    }
    $html2 = file_get_contents($f2);
    ///////////////
    $regex2 = '~</i>[^<]*(fa\-[^<]*)<~ims';
    $tmp = [];
    preg_match_all($regex2, $html2, $m2);
    foreach ($m2[1] as $v) {
        $v = trim($v);
        $tmp[$v] = $v;
    }
    ksort($tmp);
    ///////////////
    $data = [];
    foreach ($tmp as $v) {
        $id = $v;
        if (!$id) {
            continue;
        }
        $data[$id] = [
            'name' => $id,
            'active' => 1,
        ];
    }
    //foreach (range(1,20) as $c) {
    //    $data[$c]['active'] = 1;
    //}

    $f4 = __DIR__ . '/fontawesome_icons.php';
    file_put_contents($f4, '<?' . 'php' . PHP_EOL . '$data = ' . var_export($data, 1) . ';');
    print_r($data);
}

data_get_latest_icons();