PHPackages                             filipajdacic/yii2-helpers - 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. [Utility &amp; Helpers](/categories/utility)
4. /
5. filipajdacic/yii2-helpers

ActiveYii2-extension[Utility &amp; Helpers](/categories/utility)

filipajdacic/yii2-helpers
=========================

This is a set of useful helper function in one place packed to use with Yii2 framework. It will save you a lot of time.

2201PHP

Since Feb 22Pushed 7y ago1 watchersCompare

[ Source](https://github.com/filipajdacic/yii2-helpers)[ Packagist](https://packagist.org/packages/filipajdacic/yii2-helpers)[ RSS](/packages/filipajdacic-yii2-helpers/feed)WikiDiscussions master Synced 4w ago

READMEChangelogDependenciesVersions (1)Used By (0)

Yii2 Helpers - Set of useful helper functions for Yii2
======================================================

[](#yii2-helpers---set-of-useful-helper-functions-for-yii2)

This is a set of useful helper function in one place packed to use with Yii2 framework. It will save you a lot of time.

Installation
------------

[](#installation)

The preferred way to install this extension is through [composer](http://getcomposer.org/download/).

Either run

```
php composer.phar require --prefer-dist filipajdacic/yii2-helpers "*"

```

or add

```
"filipajdacic/yii2-helpers": "*"

```

to the require section of your `composer.json` file.

Usage
-----

[](#usage)

Once the extension is installed, simply use it in your code by putting this in your config:

```
'components' => array(
    ...
    'Helpers' => array(
        'class' => 'filipajdacic\yii2helpers\Helper',
    ),
    ...
);
```

**Examples:**

1. **validateEmail()** - Validates email address

```
   $email = "example@mail.com";
   $validate = Yii::$app->Helpers->validateEmail($email);
   if($validate) {
      echo 'Mail is Valid!';
   } else {
      echo 'Email is not Valid!';
   }
```

2. **encodeEmail()** - Encodes particular email address into HTML entities so that spam bots do not find it.

```
   $email = "example@mail.com";
   $encodedEmail = Yii::$app->Helpers->encode_email($email, 'Contact Me', 'class="emailencoder"');

   echo "You can feel free to ".$encodedEmail;
```

3. **highlight\_text()** - It becomes convenient for user, when he searches something and in the result he can see his keyword highlighted.

    ```
     $text = "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Quisque condimentum, augue vel finibus suscipit, erat lacus mollis urna, nec placerat nibh ex non felis. Morbi sit amet imperdiet dui. Lorem, Praesent pharetra sed orci in mollis. Pellentesque consectetur, turpis eu imperdiet feugiat, ipsum diam semper libero, eget mollis quam odio ullamcorper ligula. ";

     $highlighted_text = Yii::$app->Helpers->highlight_text($text, "Lorem", '#4285F4')

     echo'Your search results for word: Lorem are highlighted: ';
     echo ''.$highlighted_text.'';
    ```
4. **truncateText()** - You can truncate text and specify number of characters you want to show. It also supports &gt;adding a sufix at the end of the truncated strings (ex: read more..)

    ```

     $text = "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Quisque condimentum, augue vel finibus suscipit, erat lacus mollis urna, nec placerat nibh ex non felis. Morbi sit amet imperdiet dui. Lorem, Praesent pharetra sed orci in mollis. Pellentesque consectetur, turpis eu imperdiet feugiat, ipsum diam semper libero, eget mollis quam odio ullamcorper ligula. ";

     $short_version = Yii::$app->Helpers->truncateText($text, 30, ' read more...');

     echo '';
         echo ''.$short_version.'';
     echo '';
    ```
5. **cleanText()** - This function clean any text by removing unwanted tags. You can use this function to filter for example an textarea value and strip unwanted tags in text.

```
   $commentBody = "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Quisque condimentum, augue vel finibus suscipit, erat lacus mollis urna, nec placerat nibh ex non felis. Morbi sit amet imperdiet dui.  alert('I am hacker!');  or Click here to see my picture ' ";

   $comment_cleared = Yii::$app->Helpers->clearText($commentBody);
   echo '';
       echo ''.$comment_cleared.'';
   echo '';
```

6. **generateSlug()** - This function is useful if you would like to generate clean URL Slug.

```
    $post_title = "Hey this Helpers will really help you!";
    $url_slug = Yii::$app->Helpers->generateSlug($post_title);

    echo "".$post_title."";
```

7. **getTinyurl();** - Url Shortener using TinyUrl which returns a TinyUrl short URL for provided long URL.

```
    $raw_url  = "https://github.com/filipajdacic";
    $tiny = Yii::$app->Helpers->getTinyurl($raw_url);
    echo $tiny;
```

8. **base64url\_encode();** - Encodes a URL string to a Base64 URL.

```
    $url = "http://github.com/filipajdacic";
    $encoded_url = Yii::$app->Helpers->base64_encode($url);
    // output will be: aHR0cDovL2dpdGh1Yi5jb20vZmlsaXBhamRhY2lj
```

9. **base64url\_decode();** - Decodes a Base64 URL to plain text.

```
    $url = "aHR0cDovL2dpdGh1Yi5jb20vZmlsaXBhamRhY2lj";
    $decoded_url = Yii::$app->Helpers->base64_decode($url);
    // output will be: http://github.com/filipajdacic
```

10. **timeAgo();** - This function convert a date and time string into xx time ago. Give the data and time string in this format: yyyy-mm-dd hh:ii:ss and it will return you the time ago.

```
    $post_created_on = "2016-06-11 11:04:32";
    $post_created_on_ago = Yii::$app->Helpers->timeAgo($post_created_on);
    // output will be: 6 months ago

    // But if you try like this:
     $post_created_on_ago = Yii::$app->Helpers->timeAgo($post_created_on,true);
    // output will be: 6 months 1 week, 23 hours, 51 minutes, 21 seconds ago
```

11. **showYoutube();** - This function replaces all YouTube link into video object (iframe).

```
   $youtube_link = "https://www.youtube.com/watch?v=L7oo21yfl7s";
   $youtube_player = Yii::$app->Helpers->showYoutube($youtube_link);
   echo $youtube_player;
```

12. **showVimeo();** - This function replaces all Vimeo link into video object (iframe).

```
   $vimeo_link = "https://vimeo.com/ondemand/indiegamethemovie/84887593";
   $vimeo_player = Yii::$app->Helpers->showVimeo($vimeo_link);
   echo $vimeo_player;
```

13. **showGravatar();** - Get either a Gravatar URL or complete image tag for a specified email address.

```
  $email = "ajdasoft@gmail.com";
  $gravatar = Yii::$app->Helpers->showGravatar($email);

  echo "";
   echo " ";
  echo "";
```

14. **showIP();** - This function get real ip address.

```
    $ip_address = Yii::$app->Helpers->showIP();
    echo "Your IP address is:".$ip_address;
```

15. **qr\_code();** - This method can be used to generate a QR Code image.

```
    $link = "http://github.com/filipajdacic";
    $qr_link = Yii::$app->Helpers->qr_code($link, 'URL');

    $email = "ajdasoft@gmail.com";
    $qr_email = Yii::$app->Helpers->qr_code($email, 'EMAIL');

    $telephone = "+3816122233331";
    $qr_phone = Yii::$app->Helpers->qr_code($telephone, 'TEL');

    $text = "See ya! How are you?";
    $qr_text = Yii::$app->Helpers->qr_code($text, 'TXT');
```

16. **getDistanceBetweenCordinates();** -This method can be used to calculate distance between two coordinates.

```
    $lat_1 = '44.8014766';
    $long_1 = '20.4516869';

    $lat_2 = '44.7188265';
    $long_2 = '21.1762609';

    $distance = Yii::$app->Helpers->getDistanceBetweenCoordinates($lat_1, $long_1, $lat_2, $long_2);

    foreach ($distance as $unit => $value) {
        echo $unit.': '.number_format($value,4).'';
    }
```

17. **pre\_dump();** - Pretty dump.

```

    $data = array("One", "Two", "Three");
    Yii::$app->Helpers->pre_dump($data);
```

### Version

[](#version)

1.0 License
-----------

[](#10license)

MIT

###  Health Score

22

—

LowBetter than 21% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity14

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity38

Early-stage or recently created project

 Bus Factor1

Top contributor holds 91.7% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

### Community

Maintainers

![](https://www.gravatar.com/avatar/becb9ce4255f33cb29107dd9f78b7aa77dfef7f23f6847d5c8124e6016f2880c?d=identicon)[filipajdacic](/maintainers/filipajdacic)

---

Top Contributors

[![filipajdacic](https://avatars.githubusercontent.com/u/4216693?v=4)](https://github.com/filipajdacic "filipajdacic (11 commits)")[![opiy-org](https://avatars.githubusercontent.com/u/10293975?v=4)](https://github.com/opiy-org "opiy-org (1 commits)")

### Embed Badge

![Health badge](/badges/filipajdacic-yii2-helpers/health.svg)

```
[![Health](https://phpackages.com/badges/filipajdacic-yii2-helpers/health.svg)](https://phpackages.com/packages/filipajdacic-yii2-helpers)
```

###  Alternatives

[bissolli/nova-phone-field

Nova Phone Number field with a dynamic mask based on the country code inserted by the user.

31407.9k1](/packages/bissolli-nova-phone-field)[drehimself/laravelgooglemaps

Laravel Google Map package for 5.x. You can use all google map features in laravel.

331.1k](/packages/drehimself-laravelgooglemaps)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
