toneflix-code/fontawsome5-php

允许您在PHP项目中使用fontawsome 5图标。

v1.0.3 2021-12-29 00:10 UTC

This package is auto-updated.

Last update: 2024-09-29 05:50:07 UTC


README

Latest Version on Packagist Software License Total Downloads

这是一个围绕Font Awesome 5的PHP包装器,允许您在PHP项目中调用和使用fontawesome 5图标。

要求

  • PHP 5.4.0或更高版本
  • Font Awesome 5.15.3或更高版本

安装

通过Composer

    $ composer require toneflix-code/fontawsome5-php

通过下载

发行页面下载一个发布版本。解压后

    require 'path/to/src/autoload.php';

使用方法

0. 首先

这个库不提供Font Awesome,请确保满足该依赖项。根据您拥有的FontAwesome,可能需要将LICENSE设置为[free, pro, all]中的任何一个,并且也可能需要将$icon_type设置为[brands, duotone, light, regular, solid, all]中的任何一个。

1. 初始化

通过调用FontAwesome()类来初始化

    $font_awesome = new \ToneflixCode\FontAwesome(LICENSE);

2. 图标数组

获取一个包含所有可用图标的数组,这些图标由您提供的参数确定

    $icon_type = "solid";   //The type of icons you are requesting for
    $icons     = $font_awesome->icons($icon_type);
    print_r($icons);

3. HTML选择

该库可以帮助您生成一个带有图标选项的HTML选择,预期的示例如下

    <select name="icon" class="icon-class">
        <option value="fas fa-fa-500px">500px</option>
    </select>

实现可以很容易地完成

    $icon_type = "solid";           //The type of icons you are requesting for
    $selected  = 'fas fa-fa-500px'; //The currently selected icon
    $class     = "form-control";    //The class to be added to select html element
    $titles    = true;              //Setting this to true will apply a ucwords() function 
                                    //and remove all [-] to an icon then make it a title

    $icons     = $font_awesome->selector($selected, $class, $titles, $icon_type);
    echo $icons;

许可证

MIT许可证(MIT)。有关更多信息,请参阅许可证文件