PHPackages                             lastguest/dynamic-string - 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. [Templating &amp; Views](/categories/templating)
4. /
5. lastguest/dynamic-string

ActiveLibrary[Templating &amp; Views](/categories/templating)

lastguest/dynamic-string
========================

Template based random string generator

1.0.0(11y ago)272136MITPHPPHP &gt;=5.4

Since Jan 13Pushed 9y ago2 watchersCompare

[ Source](https://github.com/lastguest/DynamicString)[ Packagist](https://packagist.org/packages/lastguest/dynamic-string)[ Docs](https://github.com/lastguest/DynamicString)[ RSS](/packages/lastguest-dynamic-string/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (1)DependenciesVersions (2)Used By (0)

DynamicString
=============

[](#dynamicstring)

> Generate random strings from templates.

[![Latest Stable Version](https://camo.githubusercontent.com/7aec1f2e190d5c8e0d18e5b7869fd438651bb88fe0c8ab11e0de571ca8615640/68747470733a2f2f706f7365722e707567782e6f72672f6c61737467756573742f64796e616d69632d737472696e672f762f737461626c652e737667)](https://packagist.org/packages/lastguest/dynamic-string) [![Total Downloads](https://camo.githubusercontent.com/2d21a9cab4d7229f3bdf20f8933db03115ccc59376560fe8a2e62ed9280b8d9c/68747470733a2f2f706f7365722e707567782e6f72672f6c61737467756573742f64796e616d69632d737472696e672f646f776e6c6f6164732e737667)](https://packagist.org/packages/lastguest/dynamic-string) [![Latest Unstable Version](https://camo.githubusercontent.com/5682ce0617696db091022cbc7cf1900334c15d3c46f37d05d90713b4d453d486/68747470733a2f2f706f7365722e707567782e6f72672f6c61737467756573742f64796e616d69632d737472696e672f762f756e737461626c652e737667)](https://packagist.org/packages/lastguest/dynamic-string) [![License](https://camo.githubusercontent.com/5f63d5187b05abf07eaf6daeff5a100649a9a5e732a2dbcd297d0d79e54c3828/68747470733a2f2f706f7365722e707567782e6f72672f6c61737467756573742f64796e616d69632d737472696e672f6c6963656e73652e737667)](https://packagist.org/packages/lastguest/dynamic-string)

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

[](#installation)

Install via [composer](https://getcomposer.org/download/):

```
$ composer require lastguest/dynamic-string
```

### How to use

[](#how-to-use)

```
$generator = new DynamicString();
echo $generator->render("I want a (fried|double|spicy) (tuna|salmon|crab) (sushi|(ura|te)maki), please.");
```

### Templates

[](#templates)

Use `()` for define a group that will be replaced by one of the contained alternatives, random selected.

The `|` character is used as a separator for multiple choices.

This template will render `Yes` or `No` randomly :

```
(Yes|No)

```

Groups can be nested, they will resolved with a deep-first order.

This template will render `Finger`, `Fingers`, `Hand`, `Hands` randomly :

```
(Finge(r|rs)|Han(d|ds))

```

A complete template for generate random Sushi orders :

```
I want a (fried|double|spicy) (tuna|salmon|crab) (sushi|(ura|te)maki), please.

```

Some outputs :

```
I want a spicy salmon sushi, please.
I want a double tuna uramaki, please.
I want a double salmon temaki, please.
I want a spicy crab sushi, please.

```

### Changing default group envelope and separator

[](#changing-default-group-envelope-and-separator)

You can change the default group envelope and separator in the `DynamicString` constructor.

```
$generator = new DynamicString('',',');
echo $generator->render(" function( myVar){};");
```

Output:

```
private function(array myVar){};

```

### Other examples

[](#other-examples)

A fun use for DynamicString: a fantasy RPG stories generator.

```
$generator = new DynamicString();

$name = "(Quick|Fast|Wet|Rusty|Warm|Curved|Old|Terror|Notched|Smelly|Loud|Heavy|Shiny|Sparkling|Fire|Laser|Cold|Fizzle|Power|Bad|Good|Rustle|Dark|Smokey|Super|Fishy|Pointy|Flash|Beauty|Bleeding|Foo|Master|Small|Big|Red|Gray|Hairy|Magic|Broken|Sharp|Grand|Straight)(mind|blower|killer|hand|ey(e|es)|fee(t|ts)|finge(r|rs)|nose|armpi(t|ts)|blaster|rhymes|bar|sword|blade|breath)";

$race = "(lion|human|worm|rat|orc|elf|pixie|walrus|rooster|dog|parrot|rabbit)";
$class = "(rogue|paladin|warrior|cook|cleric|psychopath|fisherman|wolf)";
$player = "$name, the $race $class.";

$sillystory = "(A (sloppy|quick|brave|small|gentle|cruel|fabulous|shiny) $class $race, named $name) (jumped onto|walked to|crawled under|entered|sprinted to|runned into) a( rooftop| bridge|n house| wormhole|n inn| dungeon) (shouting|whispering|saying|barfing|asking for) ((ancient|magic|modern|silly|awkward) (words|names|runes|spells|shouts|rhimes|swears|songs|tacos)).";
```

Now, we can generate a silly story with :

```
echo $generator->render($sillystory);
```

Some examples :

```
A cruel rogue orc, named Smellyarmpits jumped onto an house barfing magic tacos.
A fabulous paladin pixie, named Graybar jumped onto a rooftop shouting silly runes.
A brave paladin worm, named Pointyblaster runned into an inn saying awkward names.
A brave psychopath rooster, named Wetsword entered a bridge whispering silly words.
A shiny paladin worm, named Darkeyes walked to a bridge asking for awkward names.
A small psychopath rooster, named Bleedingbar crawled under an inn saying magic songs.
A sloppy warrior parrot, named Rustyblower jumped onto an house asking for ancient swears.

```

Or we can generate some fun names for our characters :

```
echo $generator->render($player);
```

```
Badblade, the rabbit cleric.
Hairykiller, the elf fisherman.
Bleedingblower, the pixie psychopath.
Notchedrhymes, the pixie paladin.
Fastfingers, the human psychopath.
Hairyfeets, the pixie fisherman.

```

License (MIT)
-------------

[](#license-mit)

Copyright (c) 2015 Stefano Azzolini

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

###  Health Score

31

—

LowBetter than 68% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity23

Limited adoption so far

Community13

Small or concentrated contributor base

Maturity58

Maturing project, gaining track record

 Bus Factor1

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

Unknown

Total

1

Last Release

4142d ago

### Community

Maintainers

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

---

Top Contributors

[![lastguest](https://avatars.githubusercontent.com/u/178900?v=4)](https://github.com/lastguest "lastguest (16 commits)")[![bitdeli-chef](https://avatars.githubusercontent.com/u/3092978?v=4)](https://github.com/bitdeli-chef "bitdeli-chef (1 commits)")

---

Tags

phpstring-manipulationtemplate-stringrandomgeneratortemplategrammar

### Embed Badge

![Health badge](/badges/lastguest-dynamic-string/health.svg)

```
[![Health](https://phpackages.com/badges/lastguest-dynamic-string/health.svg)](https://phpackages.com/packages/lastguest-dynamic-string)
```

###  Alternatives

[phpoffice/phpword

PHPWord - A pure PHP library for reading and writing word processing documents (OOXML, ODF, RTF, HTML, PDF)

7.5k34.7M186](/packages/phpoffice-phpword)[rize/uri-template

PHP URI Template (RFC 6570) supports both expansion &amp; extraction

420137.3M46](/packages/rize-uri-template)[anourvalar/office

Generate documents from existing Excel &amp; Word templates | Export tables to Excel (Grids)

24085.2k](/packages/anourvalar-office)[tightenco/jigsaw-blog-template

Blog starter template for Jigsaw static site generator by Tighten

9464.0k](/packages/tightenco-jigsaw-blog-template)[tightenco/jigsaw-docs-template

Documentation starter template for Jigsaw static site generator by Tighten

5026.9k](/packages/tightenco-jigsaw-docs-template)[tomatophp/filament-plugins

Manage your modules as a plugin system with plugin generator

644.7k2](/packages/tomatophp-filament-plugins)

PHPackages © 2026

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