PHPackages                             yassinedoghri/php-icons - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Image &amp; Media](/categories/media)
4. /
5. yassinedoghri/php-icons

ActiveLibrary[Image &amp; Media](/categories/media)

yassinedoghri/php-icons
=======================

A PHP library based on iconify's API to download and render svg icons from popular open source icon sets.

v1.3.0(1y ago)136.0k↑36.4%3[1 PRs](https://github.com/yassinedoghri/php-icons/pulls)2MITPHPPHP &gt;=8.1CI passing

Since Sep 28Pushed 2w ago1 watchersCompare

[ Source](https://github.com/yassinedoghri/php-icons)[ Packagist](https://packagist.org/packages/yassinedoghri/php-icons)[ RSS](/packages/yassinedoghri-php-icons/feed)WikiDiscussions develop Synced 2d ago

READMEChangelog (4)Dependencies (9)Versions (8)Used By (2)

PHPIcons 🐘 🙂
============

[](#phpicons--)

**A convenient PHP library to render svg icons.**

[![Latest Stable Version](https://camo.githubusercontent.com/0aeaa85c59cb6a240a0c0e2c20222f0ef38d387605501c058a0bd329c8459f93/68747470733a2f2f706f7365722e707567782e6f72672f79617373696e65646f676872692f7068702d69636f6e732f76)](https://packagist.org/packages/yassinedoghri/php-icons)[![Total Downloads](https://camo.githubusercontent.com/e8149ecb03592f42b2d8d631961bd1e4a5aa68f16fa5bbc24e14b3d8c20c506c/68747470733a2f2f706f7365722e707567782e6f72672f79617373696e65646f676872692f7068702d69636f6e732f646f776e6c6f616473)](https://packagist.org/packages/yassinedoghri/php-icons)[![codecov](https://camo.githubusercontent.com/e4cd83c519fbc86ffff9dd3a75a918d46626bfcc2e19d15b2b50c617e83d6070/68747470733a2f2f636f6465636f762e696f2f67682f79617373696e65646f676872692f7068702d69636f6e732f67726170682f62616467652e7376673f746f6b656e3d50384347374a35484f51)](https://codecov.io/gh/yassinedoghri/php-icons)[![License](https://camo.githubusercontent.com/573204e3e32b4442cfea304b965f3ef992203cfaac3ac05e82efeb97241f980d/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6c6963656e73652f79617373696e65646f676872692f7068702d69636f6e733f636f6c6f723d677265656e)](https://packagist.org/packages/yassinedoghri/php-icons)[![PHP Version Require](https://camo.githubusercontent.com/162f12952d8f74096a6d943786bc8cc03d1111aec2ce8d40f875bedcac37badf/68747470733a2f2f706f7365722e707567782e6f72672f79617373696e65646f676872692f7068702d69636f6e732f726571756972652f706870)](https://packagist.org/packages/yassinedoghri/php-icons)

Get access to over 200,000 icons from more than [150 open source icon sets](https://icon-sets.iconify.design/) directly from your php files!

Thanks to [Iconify](https://iconify.design/) ❤️

🚀 Getting started
-----------------

[](#-getting-started)

### 1. Install via composer

[](#1-install-via-composer)

```
composer require yassinedoghri/php-icons
```

### 2. Configure

[](#2-configure)

Run the following command to initialize the configuration file:

```
vendor/bin/php-icons init
```

This will prompt you to create a `php-icons.php` config file in the root of your project. See [config reference](#%E2%9A%99%EF%B8%8F-config-reference) for more info.

### 3. Use anywhere

[](#3-use-anywhere)

#### 3.1. `icon(string $iconKey, array $attributes)` function

[](#31-iconstring-iconkey-array-attributes-function)

Use the global `icon(…)` function in your view files with the icon key (`{prefix}:{icon}`) as parameter:

- `{prefix}`: is the [icon set prefix](https://iconify.design/docs/icons/icon-set-basics.html#naming)
- `{name}`: is the [icon name](https://iconify.design/docs/icons/icon-basics.html#icon-names)

```
echo icon('material-symbols:bolt');
//
//
//
```

👉 To add attributes, use the second parameter or call the `attr()` or `attributes()` methods:

```
echo icon('material-symbols:bolt', [
        'class' => 'text-2xl',
        'style' => 'color: yellow;'
     ]);
// …

echo icon('material-symbols:bolt')
      ->attr('class', 'text-2xl')
      ->attr('style', 'color: yellow;');
// …

echo icon('material-symbols:bolt')
      ->attributes([
        'class' => 'text-2xl',
        'style' => 'color: yellow;'
      ]);
// …
```

Tip

Find and copy the icon keys of popular open source icon sets from [Iconify's index](https://icon-sets.iconify.design/).

#### 3.2. Scan source files to load icons

[](#32-scan-source-files-to-load-icons)

Important

When first defining icons, a placeholder (`�` by default) will be displayed.
Make sure to run the `scan` command to load the SVGs.

```
vendor/bin/php-icons scan
```

The `scan` command will perform a static analysis of all PHP files in your [configured paths](#paths) to identify icon keys (`{prefix}:{name}`) and download the corresponding icons.

Using the `icon` identifier by default:

1. `icon(…)` functions

    ```
     echo icon('ri:php-fill')    // identified "ri:php-fill"
    ```
2. `@icon(…)` annotations in comments

    ```
      // @icon('ri:heart-fill') --> identified "ri:heart-fill"

      # @icon('ri:home-fill')   --> identified "ri:home-fill"

      /*
       * @icon('ri:user-fill')  --> identified "ri:user-fill"
       * @icon('ri:group-fill') --> identified "ri:group-fill"
       */
    ```

⚙️ Config reference
-------------------

[](#️-config-reference)

Your config file is loaded by both the `php-icons` CLI tool and PHPIcons class, it should look like this:

```
