PHP code example of awps / font-awesome-php

1. Go to this page and download the library: Download awps/font-awesome-php library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

awps / font-awesome-php example snippets


composer 



// Using the reader to dynamically get the icons array. It's resource intensive and you must cache the result.
$css_path = __DIR__ . '/css/font-awesome.css';
$icons    = new Awps\FontAwesomeReader( $css_path );

// .... or better use the static class

$icons = new Awps\FontAwesome();

$icons->getArray();

// Result:
/*
array (
  'fa-glass' => '\\f000',
  'fa-music' => '\\f001',
  'fa-search' => '\\f002',
  ...
*/

$icons->getAllData();

// Result:
/*
array (
  'fa-glass' => 
  array (
    'unicode' => '\\f000',
    'name' => 'Glass',
    'class' => 'fa-glass',
  ),
  'fa-music' => 
  array (
    'unicode' => '\\f001',
    'name' => 'Music',
    'class' => 'fa-music',
  ),
  ...
*/

$icons->getCssClasses();

// Result:
/*
array (
  'fa-glass' => 'fa-glass',
  'fa-music' => 'fa-music',
  'fa-search' => 'fa-search',
  ...
*/

$icons->getUnicodeKeys();

// Result:
/*
array (
  'fa-glass' => '\\f000',
  'fa-music' => '\\f001',
  'fa-search' => '\\f002',
  'fa-envelope-o' => '\\f003',
  ...
*/

$icons->getReadableNames();

// Result:
/*
array (
  'fa-glass' => 'Glass',
  'fa-music' => 'Music',
  'fa-search' => 'Search',
  ...
*/

$icons->sortByName();

// Result:
/*
array (
  'fa-500px' => '\\f26e',
  'fa-address-book' => '\\f2b9',
  'fa-address-book-o' => '\\f2ba',
  'fa-address-card' => '\\f2bb',
  'fa-address-card-o' => '\\f2bc',
  'fa-adjust' => '\\f042',
  ...
*/

$icons->getIconUnicode( 'fa-address-card' );

// Result
// '\f2bb'

$icons->getIconName( 'fa-address-card' );

// Result
// 'Address card'

$icons->getIcon( 'fa-address-card' );

// Result
/*
array (
  'unicode' => '\\f2bb',
  'name' => 'Address card',
  'class' => 'fa-address-card',
)
*/

$icons->getIconByUnicode( '\\f004' )

// Result
/*
array (
  'unicode' => '\\f004',
  'name' => 'Heart',
  'class' => 'fa-heart',
)
*/

$icons->sortByName();

// Array is sorted:
$icons->getArray();

/*
array (
  'fa-500px' => '\\f26e',
  'fa-address-book' => '\\f2b9',
  'fa-address-book-o' => '\\f2ba',
  'fa-address-card' => '\\f2bb',
  ...
);
*/

// Reset it
$icons->reset();

// This one will return the original array
$icons->getArray();

// Result:
/*
array (
  'fa-glass' => '\\f000',
  'fa-music' => '\\f001',
  'fa-search' => '\\f002',
  ...
);
*/