PHPackages                             basteyy/php-stringer - 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. basteyy/php-stringer

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

basteyy/php-stringer
====================

A simple php class which provides a few function for manipulating strings, get random strings and work with times/datetime objects.

1.1.1(2y ago)0511MITPHPPHP ^8.2

Since Nov 6Pushed 2y ago1 watchersCompare

[ Source](https://github.com/basteyy/php-stringer)[ Packagist](https://packagist.org/packages/basteyy/php-stringer)[ RSS](/packages/basteyy-php-stringer/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (4)Dependencies (1)Versions (5)Used By (1)

basteyy`s PHP Stringer Package
==============================

[](#basteyys-php-stringer-package)

Every developer knows the drill: Here I need a random string, there I have to generate a URL from an input, and then I want to find out how long ago an event was. This package bundles a few functions that I constantly need in my projects. You are welcome to contribute and expand it.

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

[](#installation)

```
composer require basteyy/php-stringer
```

Usage
-----

[](#usage)

To use the `basteyy\php-stringer` package in your projects, here are some examples with their expected outputs:

### String Mainiplation

[](#string-mainiplation)

#### Escape String

[](#escape-string)

For safe output of strings in an HTML context, use `escapeString`:

```
echo basteyy\Stringer\escapeString('alert("hello")');
// Output: &lt;script&gt;alert(&quot;hello&quot;)&lt;/script&gt;
```

#### Generate Hash Sum

[](#generate-hash-sum)

Create a hash sum of a string (default algorithm is SHA256) using `getStringHashSum`:

```
echo basteyy\Stringer\getStringHashSum('yourStringHere');
// Output: [sha256 hash of 'yourStringHere']
```

#### Remove Double Slashes

[](#remove-double-slashes)

Use `remove_double_slashes` to clean up file paths or URLs:

```
echo basteyy\Stringer\remove_double_slashes('https://example.com//path//');
// Output: https://example.com/path/
```

#### Slugify Text

[](#slugify-text)

Convert a string into a URL-optimized version with `getSlugifiedText`:

```
echo basteyy\Stringer\getSlugifiedText('Hello World! How are you?');
// Output: hello-world-how-are-you
```

##### Slugify (Deprecated)

[](#slugify-deprecated)

For backward compatibility, `slugify` is still available but is deprecated. It functions the same as `getSlugifiedText`:

```
echo basteyy\Stringer\slugify('This is a Test String!');
// Output: this-is-a-test-string
```

### Random String Generation

[](#random-string-generation)

#### Generate Alphanumeric String

[](#generate-alphanumeric-string)

```
echo basteyy\Stringer\getRandomAlphaNumericString(10);
// Output example: "1a2b3c4d5e"
```

#### Generate Numeric String

[](#generate-numeric-string)

```
echo basteyy\Stringer\getRandomNumericString(10);
// Output example: "1234567890"
```

#### Generate Alphabet String

[](#generate-alphabet-string)

```
echo basteyy\Stringer\getRandomAlphaString(10);
// Output example: "aBcDeFgHiJ"
```

#### Generate String with Custom Characters:

[](#generate-string-with-custom-characters)

```
echo basteyy\Stringer\getRandomString(10, '!@#$%^&*()');
// Output example: "%$@!^&*!@"
```

#### Create memorable password

[](#create-memorable-password)

The createMemorablePassword function in the basteyy\\Stringer library generates passwords that are easier to remember, combining words, numbers, and symbols. This function is not cryptographically secure and is more suitable for user-friendly passwords rather than high-security purposes.

```
$password = basteyy\Stringer\createMemorablePassword(2, 2, 2, true);
echo $password;
```

In this example, the function generates a password with:

- 2 random words from a predefined list.
- 2 random numbers.
- 2 random symbols from the default symbol set !@#$%^&amp;\*.
- Converts the password to lowercase.

The output will be a string like `apple7%cloud4*`, making it memorable yet unique. You can adjust the counts of words, numbers, and symbols as needed.

> Attention: The function `createMemorablePassword` is not cryptographically secure and should not be used for high-security.

### Time Manipulation

[](#time-manipulation)

#### Get Nice Time Ago

[](#get-nice-time-ago)

`getNiceTimeAgo` function returns a human-readable time difference from the current time to the provided DateTime.

```
// Standard usage with default unit names
echo basteyy\Stringer\Times\getNiceTimeAgo('2023-01-01 00:00:00');
// Output example: "2 months ago"

// Exact output
echo basteyy\Stringer\Times\getNiceTimeAgo('2023-01-01 00:00:00', true);
// Output example: "2 months, 3 days, 4 hours, 5 minutes, 6 seconds ago"

// Custom unit names
$customUnitMap = [
    'second' => ['Sekunde', 'Sekunden'],
    'minute' => ['Minute', 'Minuten'],
    // ... other units
];
echo basteyy\Stringer\Times\getNiceTimeAgo('2023-01-01 00:00:00', false, $customUnitMap);
// Output example: "2 Monate ago"
```

These examples showcase the versatility of the `getNiceTimeAgo` function, providing options for exact time intervals, custom unit names, and localization.

###  Health Score

26

—

LowBetter than 43% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity8

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity58

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% 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.

###  Release Activity

Cadence

Every ~2 days

Total

4

Last Release

914d ago

Major Versions

0.0.1 → 1.0.02023-11-06

PHP version history (2 changes)0.0.1PHP ^8.3

1.0.0PHP ^8.2

### Community

Maintainers

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

---

Top Contributors

[![basteyy](https://avatars.githubusercontent.com/u/2758879?v=4)](https://github.com/basteyy "basteyy (8 commits)")

---

Tags

randomphpstringdatetimetime

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/basteyy-php-stringer/health.svg)

```
[![Health](https://phpackages.com/badges/basteyy-php-stringer/health.svg)](https://phpackages.com/packages/basteyy-php-stringer)
```

###  Alternatives

[coduo/php-to-string

Simple library that converts PHP value into strings

27112.7M10](/packages/coduo-php-to-string)[kartik-v/php-date-formatter

A Javascript datetime formatting and manipulation library using PHP date-time formats.

461.5M3](/packages/kartik-v-php-date-formatter)[dater/dater

Compact PHP library for working with date/time in different formats &amp; timezones.

14282.3k](/packages/dater-dater)[zjkal/time-helper

一个简单快捷的PHP日期时间助手类库。 a smart PHP datetime helper library.

21128.6k1](/packages/zjkal-time-helper)[danielstjules/php-pretty-datetime

Generates human-readable strings for PHP DateTime objects

5791.9k](/packages/danielstjules-php-pretty-datetime)[sinergi/token

PHP library to generate random strings

188.7k9](/packages/sinergi-token)

PHPackages © 2026

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