PHPackages                             dd/evolutioncms-snippets-ddstringtools - 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. dd/evolutioncms-snippets-ddstringtools

ActiveModxevo-snippet[Utility &amp; Helpers](/categories/utility)

dd/evolutioncms-snippets-ddstringtools
======================================

Tools for modifying strings.

2.3.0(1y ago)02PHPPHP &gt;=5.6.0CI failing

Since Oct 20Pushed 1y ago2 watchersCompare

[ Source](https://github.com/DivanDesign/EvolutionCMS.snippets.ddStringTools)[ Packagist](https://packagist.org/packages/dd/evolutioncms-snippets-ddstringtools)[ Docs](https://code.divandesign.ru/modx/ddstringtools)[ RSS](/packages/dd-evolutioncms-snippets-ddstringtools/feed)WikiDiscussions master Synced 1w ago

READMEChangelog (10)Dependencies (2)Versions (13)Used By (0)

(MODX)EvolutionCMS.snippets.ddStringTools
=========================================

[](#modxevolutioncmssnippetsddstringtools)

Tools for modifying strings.

Requires
--------

[](#requires)

- PHP &gt;= 5.6
- [(MODX)EvolutionCMS](https://github.com/evolution-cms/evolution) &gt;= 1.1
- [(MODX)EvolutionCMS.libraries.ddTools](https://code.divandesign.ru/modx/ddtools) &gt;= 0.60
- [(MODX)EvolutionCMS.snippets.ddtypograph](https://code.divandesign.ru/modx/ddtypograph) &gt;= 2.6 (if the `tools->typographer` parameter is used)
- [PHP.libraries.Parsedown](https://github.com/erusev/parsedown) &gt;= 1.8.0-beta-7 (contains in archive)

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

[](#installation)

### Using [(MODX)EvolutionCMS.libraries.ddInstaller](https://github.com/DivanDesign/EvolutionCMS.libraries.ddInstaller)

[](#using-modxevolutioncmslibrariesddinstaller)

Just run the following PHP code in your sources or [Console](https://github.com/vanchelo/MODX-Evolution-Ajax-Console):

```
// Include (MODX)EvolutionCMS.libraries.ddInstaller
require_once(
	$modx->getConfig('base_path')
	. 'assets/libs/ddInstaller/require.php'
);

// Install (MODX)EvolutionCMS.snippets.ddStringTools
\DDInstaller::install([
	'url' => 'https://github.com/DivanDesign/EvolutionCMS.snippets.ddStringTools',
]);
```

- If `ddStringTools` is not exist on your site, `ddInstaller` will just install it.
- If `ddStringTools` is already exist on your site, `ddInstaller` will check it version and update it if needed.

### Manually

[](#manually)

#### 1. Elements → Snippets: Create a new snippet with the following data

[](#1-elements--snippets-create-a-new-snippet-with-the-following-data)

1. Snippet name: `ddStringTools`.
2. Description: `2.3 Tools for modifying strings.`.
3. Category: `Core`.
4. Parse DocBlock: `no`.
5. Snippet code (php): Insert content of the `ddStringTools_snippet.php` file from the archive.

#### 2. Elements → Manage Files:

[](#2-elements--manage-files)

1. Create a new folder `assets/snippets/ddStringTools/`.
2. Extract the archive to the folder (except `ddStringTools_snippet.php`).

Parameters description
----------------------

[](#parameters-description)

- `inputString`

    - Description: The input string.
    - Valid values:
        - `string`
        - The input string can also be set as a PHP object or array (e. g. for calls through `$modx->runSnippet`). In this case, it will be converted to JSON first.
            - `object`
            - `array`
    - Default value: `''`
- `tools`

    - Description: List of string tools to be applied to `inputString`. Tools are called in accordance with the specified order.
    - Valid values:
        - `stirngJsonObject` — as [JSON](https://en.wikipedia.org/wiki/JSON)
        - `stringHjsonObject` — as [HJSON](https://hjson.github.io/)
        - `stringQueryFormatted` — as [Query string](https://en.wikipedia.org/wiki/Query_string)
        - It can also be set as a PHP object or array (e. g. for calls through `$modx->runSnippet`).
            - `arrayAssociative`
            - `object`
    - Default value: `'{}'`
- `tools->{$toolName}`

    - Description: A tool, when the key is the tool name and the value is the tool parameters.
        - Tool names are case insensitive (the following names are equal: `caseConverter`, `Caseconverter`, `caseconverter`, etc).
    - Valid values:
        - `object` — an object with tool parameters (see below)
        - `boolean` — for simple tools without parameters or if you need to use default parameters (if possible), just pass `true`
    - Default value: —.

### Case converter

[](#case-converter)

- `tools->caseConverter`

    - Description: Perform case folding on a string. Unicode is supported.
    - Valid values: `object`
    - Default value: —.
- `tools->caseConverter->toLower`

    - Description: Make a string lowercase.
    - Valid values: `boolean`
    - Default value: `false`
- `tools->caseConverter->toUpper`

    - Description: Make a string uppercase.
    - Valid values: `boolean`
    - Default value: `false`

### Markdown parser

[](#markdown-parser)

- `tools->markdownParser`

    - Description: Parse Markdown using Parsedown library.
    - Valid values:
        - `boolean` — if you need to parse with default params, just pass `true`
        - `object` — or an object with parameters (see below)
    - Default value: `false`
- `tools->markdownParser->parseInline`

    - Description: Parse only inline elements.
    - Valid values: `boolean`
    - Default value: `false`

### Typographer

[](#typographer)

- `tools->typographer`

    - Description: Typography text using EvolutionCMS.snippets.ddTypograph.
        - Parameters have to be passed to EvolutionCMS.snippets.ddTypograph.
        - More info in its [documentation](https://code.divandesign.ru/modx/ddtypograph).
    - Valid values:
        - `boolean` — if you need to typography with default params, just pass `true`
        - `object` — or an object with parameters (see below)
    - Default value: `false`
- `tools->typographer->optAlign`

    - Description: Optical alignment (hanging punctuation).
    - Valid values: `boolean`
    - Default value: `false`
- `tools->typographer->optAlign_useClasses`

    - Description: Use CSS classes instead of inline styles for optical alignment (`` instead of ``).
        - If the parameter is enabled, don't forget to specify the following CSS rules on your site: ```
             .oa_obracket_sp_s {margin-right:0.3em;}
             .oa_obracket_sp_b {margin-left:-0.3em;}
             .oa_obracket_nl_b {margin-left:-0.3em;}
             .oa_comma_b {margin-right:-0.2em;}
             .oa_comma_e {margin-left:0.2em;}
             .oa_oquote_nl {margin-left:-0.44em;}
             .oa_oqoute_sp_s {margin-right:0.44em;}
             .oa_oqoute_sp_q {margin-left:-0.44em;}
            ```
    - Valid values:
        - `0`
        - `1`
    - Default value: `0`
- `tools->typographer->text_paragraphs`

    - Description: Section signs and line breaks insertion.
    - Valid values: `boolean`
    - Default value: `false`
- `tools->typographer->text_autoLinks`

    - Description: Marking links (including email ones).
    - Valid values: `boolean`
    - Default value: `false`
- `tools->typographer->etc_unicodeConvert`

    - Description: Convert HTML entities into Unicode (`—` instead of `&mdash;`, etc).
    - Valid values: `boolean`
    - Default value: `true`
- `tools->typographer->noTags`

    - Description: Whether HTML element insertion is allowed or not.
        - There are cases when using tags causes the text to be invalid, for example, using the snippet inside of an HTML attribute.
    - Valid values: `boolean`
    - Default value: `false`
- `tools->typographer->excludeTags`

    - Description: HTML tags which content will be ignored by snippet.
    - Valid values: `stringCommaSeparated`
    - Default value: `'notg,code'`

### Tag remover

[](#tag-remover)

- `tools->tagRemover`

    - Description: Strip HTML and PHP tags from a string.
    - Valid values:
        - `boolean` — if you need to remove all tags, just pass `true`
        - `object` — or an object with parameters (see below)
    - Default value: `false`
- `tools->tagRemover->allowed`

    - Description: Use the parameter to specify tags which should not be stripped (e. g. ``).
    - Valid values: `string`
    - Default value: `''`

### Special char converter

[](#special-char-converter)

- `tools->specialCharConverter`
    - Description: Convert special characters to HTML entities.
    - Valid values: `boolean`
    - Default value: `false`

### Chars escaper (e. g. for JS)

[](#chars-escaper-e-g-for-js)

- `tools->charEscaper`

    - Description: Escape special characters for JS.
    - Valid values:
        - `boolean` — if you need to escape with default params, just pass `true`
        - `object` — or an object with parameters (see below)
    - Default value: `false`
- `tools->charEscaper->backslashes`

    - Description: Escape backslashes (`'\\'` will be replaced to `'\\\\'`).
    - Valid values: `boolean`
    - Default value: `true`
- `tools->charEscaper->lineBreaks`

    - Description: Escape line breaks (`"\r\n"`, `"\r"`, `"\n"` will be replaced to `'\r\n'`).
    - Valid values: `boolean`
    - Default value: `true`
- `tools->charEscaper->tabs`

    - Description: Escape tabs (`'	'` (tab) will be replaced to `' '` (space)).
    - Valid values: `boolean`
    - Default value: `true`
- `tools->charEscaper->modxPlaceholders`

    - Description: Escape (MODX)EvolutionCMS placeholders (`'[+'` and `'+]'` will be replaced to `'\[\+'` and `'\+\]'`).
    - Valid values: `boolean`
    - Default value: `true`
- `tools->charEscaper->quotes`

    - Description: Escape quotes (`"'"` and `'"'` will be replaced to `"\'"` and `'\"'`).
    - Valid values: `boolean`
    - Default value: `true`

### URL encoder

[](#url-encoder)

- `tools->urlEncoder`
    - Description: URL-encode according to RFC 3986.
    - Valid values: `boolean`
    - Default value: `false`

### Placeholder remover

[](#placeholder-remover)

- `tools->placeholderRemover`
    - Description: Remove placeholders like `[+placeholder+]`.
    - Valid values: `boolean`
    - Default value: `false`

### Preg replacer

[](#preg-replacer)

- `tools->pregReplacer`

    - Description: Perform a regular expression search and replace.
    - Valid values: `object`
    - Default value: —
- `tools->pregReplacer->pattern`

    - Description: The pattern to search for.
        - You can omit `/`, the default will be `/` + `/u`.
    - Valid values: `string`
    - **Required**
- `tools->pregReplacer->replacement`

    - Description: The string to replace.
    - Valid values: `string`
    - Default value: `''`

### Numberer

[](#numberer)

- `tools->numberer`

    - Description: Convert and format numbers.
    - Valid values: `object`
    - Default value: —
- `tools->numberer->isFloatAllowed`

    - Description: Float number availability status.
    - Valid values: `boolean`
    - Default value: `true`
- `tools->numberer->decimalsNumber`

    - Description: Number of chars standing after comma.
    - Valid values:
        - `integer`
        - `0` — any
    - Default value: `0`
- `tools->numberer->isDecimalsFixed`

    - Description: Allows formatting a number using fixed-point notation (e. g. `10.00`) according to `tools->numberer->decimalsNumber`.
    - Valid values: `boolean`
    - Default value: `false`
- `tools->numberer->thousandsSeparator`

    - Description: Character used to separate thousands (e. g. `' '` for `1 234 567` or `','` for `1,234,567`).
    - Valid values: `string`
    - Default value: `''`

### Tpl parser

[](#tpl-parser)

- `tools->tplParser`

    - Description: Gets the chunk contents by its name and parse it.
        - If `inputString` is empty, the chunk content will not be returned, just an empty string.
    - Valid values: `object`
    - Default value: —
- `tools->tplParser->tpl`

    - Description: Chunk name or code via `@CODE:` prefix.
        - Available placeholders:
            - `[+snippetResult+]` — the `inputString` modified by previous tools
    - Valid values:
        - `stringChunkName`
        - `string` — use inline templates starting with `@CODE:`
    - **Required**
- `tools->tplParser->placeholders`

    - Description: Additional data has to be passed into the `tools->tplParser->tpl`.
        - Nested objects and arrays are supported too:
            - `{"someOne": "1", "someTwo": "test" }` =&gt; `[+someOne+], [+someTwo+]`.
            - `{"some": {"a": "one", "b": "two"} }` =&gt; `[+some.a+]`, `[+some.b+]`.
            - `{"some": ["one", "two"] }` =&gt; `[+some.0+]`, `[+some.1+]`.
    - Valid values: `object`
    - Default value: —

Examples
--------

[](#examples)

All examples are written using [HJSON](https://hjson.github.io/), but if you want you can use vanilla JSON instead.

### Convert characters to lowercase (`tools->caseConverter->toLower`)

[](#convert-characters-to-lowercase-tools-caseconverter-tolower)

```
[[ddStringTools?
	&inputString=`Some STRING with DiFFerEnt case`
	&tools=`{
		caseConverter: {
			toLower: true
		}
	}`
]]

```

Returns:

```
some string with different case

```

### Strip HTML and PHP tags from a string (`tools->tagRemover`)

[](#strip-html-and-php-tags-from-a-string-tools-tagremover)

#### Remove all tags completely

[](#remove-all-tags-completely)

```
[[ddStringTools?
	&inputString=`Some sample text.`
	&tools=`{
		tagRemover: true
	}`
]]
```

Returns:

```
Some sample text.
```

#### Remove all tags except `` and `` (`tools->tagRemover->allowed`)

[](#remove-all-tags-except-p-and-a-tools-tagremover-allowed)

If you want to preserve some tags, pass an object with property `allowed` instead of `true`.

```
[[ddStringTools?
	&inputString=`Some sample text.`
	&tools=`{
		tagRemover: {
			allowed: ""
		}
	}`
]]
```

Returns:

```
Some sample text.
```

### Convert special characters to HTML entities (`tools->specialCharConverter`)

[](#convert-special-characters-to-html-entities-tools-specialcharconverter)

```
[[ddStringTools?
	&inputString=`Some sample text.`
	&tools=`{
		specialCharConverter: true
	}`
]]
```

Returns:

```
&lt;p&gt;Some &lt;a href="#"&gt;sample&lt;/a&gt; text.&lt;/p&gt;
```

### URL-encode according to RFC 3986 (`tools->urlEncoder`)

[](#url-encode-according-to-rfc-3986-tools-urlencoder)

```
[[ddStringTools?
	&inputString=`tags[]=Maps&tags[]=URLs`
	&tools=`{
		urlEncoder: true
	}`
]]

```

Returns:

```
tags%5B%5D%3DMaps%26tags%5B%5D%3DURLs

```

### Escape special characters for JavaScript (`tools->charEscaper`)

[](#escape-special-characters-for-javascript-tools-charescaper)

```

	$('body').append('[[ddStringTools?
		&inputString=`
			Some sample text.
			New line.
		`
		&tools=`{
			charEscaper: true
		}`
	]]');

```

Returns:

```

	$('body').append('\r\n Some sample text.\r\n New line.\r\n ');

```

### Convert Markdown to HTML (`tools->markdownParser`)

[](#convert-markdown-to-html-tools-markdownparser)

```
[[ddStringTools?
	&inputString=`
# Markdown example

Some text in _Markdown_.
	`
	&tools=`{
		markdownParser: true
	}`
]]

```

Returns:

```
Markdown example
Some text in Markdown.
```

#### You can also parse inline markdown only (`tools->markdownParser->parseInline`)

[](#you-can-also-parse-inline-markdown-only-tools-markdownparser-parseinline)

```
[[ddStringTools?
	&inputString=`Some text in _Markdown_.`
	&tools=`{
		"markdownParser": {
			"parseInline": true
		}
	}`
]]

```

Returns:

```
Some text in Markdown.
```

### Typography text (`tools->typographer`)

[](#typography-text-tools-typographer)

#### With optical alignment (`tools->typographer->optAlign`)

[](#with-optical-alignment-tools-typographer-optalign)

```
[[ddStringTools?
	&inputString=`Some text containing "quoted" text.`
	&tools=`{
		typographer: {
			optAlign: true
		}
	}`
]]
```

Returns:

```
Some text containing “quoted” text.
```

#### Simple call with default parameters

[](#simple-call-with-default-parameters)

```
[[ddStringTools?
	&inputString=`Some text for typography.`
	&tools=`{
		typographer: true
	}`
]]
```

### Remove placeholders like `[+placeholder+]` (`tools->placeholderRemover`)

[](#remove-placeholders-like-placeholder-tools-placeholderremover)

```
[[ddStringTools?
	&inputString=`Some [+thing+] with [+placeholder1+] and [+placeholder2+].`
	&tools=`{
		placeholderRemover: true
	}`
]]
```

Returns:

```
Some  with  and .
```

### Thumbnail suffix (`tools->pregReplacer`)

[](#thumbnail-suffix-tools-pregreplacer)

```
[[ddStringTools?
	&inputString=`assets/images/someImage.png`
	&tools=`{
		pregReplacer: {
			pattern: (.*)(\.\D*)
			replacement: $1_50x50$2
		}
	}`
]]

```

Returns:

```
assets/images/someImage_50x50.png

```

### Numberer (`tools->numberer`)

[](#numberer-tools-numberer)

#### Convert string to integer

[](#convert-string-to-integer)

```
[[ddStringTools?
	&inputString=`42.75`
	&tools=`{
		numberer: {
			isFloatAllowed: false
		}
	}`
]]

```

Returns: `42`

#### Convert string to float with maximum 2 decimal places

[](#convert-string-to-float-with-maximum-2-decimal-places)

```
[[ddStringTools?
	&inputString=`42.7589`
	&tools=`{
		numberer: {
			decimalsNumber: 2
		}
	}`
]]

```

Returns: `'42.76'`

#### Format product price with fixed decimal places

[](#format-product-price-with-fixed-decimal-places)

```
[[ddStringTools?
	&inputString=`1999`
	&tools=`{
		numberer: {
			decimalsNumber: 2
			isDecimalsFixed: true
		}
	}`
]]

```

Returns: `'1999.00'`

#### Format large number with space as thousands separator

[](#format-large-number-with-space-as-thousands-separator)

```
[[ddStringTools?
	&inputString=`1234567`
	&tools=`{
		numberer: {
			thousandsSeparator: ' '
		}
	}`
]]

```

Returns: `'1 234 567'`

#### Format price with comma as thousands separator and fixed decimal places

[](#format-price-with-comma-as-thousands-separator-and-fixed-decimal-places)

```
[[ddStringTools?
	&inputString=`1234567.891`
	&tools=`{
		numberer: {
			decimalsNumber: 2
			isDecimalsFixed: true
			thousandsSeparator: ','
		}
	}`
]]

```

Returns: `'1,234,567.89'`

#### Parse price string with currency symbol, spaces and other invalid chars

[](#parse-price-string-with-currency-symbol-spaces-and-other-invalid-chars)

```
[[ddStringTools?
	&inputString=`$1 234 000.56 lorem ipsum`
	&tools=`{
		numberer: true
	}`
]]

```

Returns: `'1234000.56'`

### Get the chunk content and pass some placeholders (`tools->tplParser`)

[](#get-the-chunk-content-and-pass-some-placeholders-tools-tplparser)

```
[[ddStringTools?
	&inputString=`Some input string text.`
	&tools=`{
		tplParser: {
			tpl:
				'''
				@CODE:[+before+][+snippetResult+][+after+]
				'''
			placeholders: {
				before:
					'''
					Some start text.
					'''
				after:
					'''
					Some end text.
					'''
			}
		}
	}`
]]
```

Returns:

```
Some start text.Some input string text.Some end text.

```

### Use multiple tools together

[](#use-multiple-tools-together)

```
[[ddStringTools?
	&inputString=`Some sample text. [+somePlaceholder+].`
	&tools=`{
		placeholderRemover: true
		typographer: true
		tagRemover: {
			allowed: ""
		}
		caseConverter: {
			toLower: true
		}
		charEscaper: true
	}`
]]
```

Tools are called in accordance with the specified order:

1. First placeholders like `[+somePlaceholder+]` will removed, then
2. Text will typographied,
3. All HTML tags except `` and `` will removed,
4. Text will converted to lowercase,
5. And escaped for JS.

### Pass `inputString` as an array through `$modx->runSnippet`

[](#pass-inputstring-as-an-array-through-modx-runsnippet)

The input string can also be set as a PHP object or array (e. g. for calls through `$modx->runSnippet`). In this case, it will be converted to JSON first.

```
$modx->runSnippet(
	'ddStringTools',
	[
		// This is an array, not string
		'inputString' => [
			'someObjectField' => '[+somePlaceholder+] need to be removed.',
			// And this is an array too
			'otherObjectField' => [
				'deepField' => '[+placeholders+] will be removed in any depth.',
			],
		],
		'tools' => [
			'placeholderRemover' => true,
		],
	]
);
```

Returns:

```
{
	"someObjectField": " need to be removed.",
	"otherObjectField": {
		"deepField": " will be removed in any depth."
	}
}
```

### Run the snippet through `\DDTools\Snippet::runSnippet` without DB and eval

[](#run-the-snippet-through-ddtoolssnippetrunsnippet-without-db-and-eval)

```
// Include (MODX)EvolutionCMS.libraries.ddTools
require_once(
	$modx->getConfig('base_path')
	. 'assets/libs/ddTools/modx.ddtools.class.php'
);

// Run (MODX)EvolutionCMS.snippets.ddStringTools
\DDTools\Snippet::runSnippet([
	'name' => 'ddStringTools',
	'params' => [
		'inputString' => 'Some sample text. [+somePlaceholder+].',
		// `tools` in this case can be set as a native PHP array or object
		'tools' => [
			'placeholderRemover' => true,
			'typographer' => true,
			'tagRemover' => [
				'allowed' => '',
			],
			'caseConverter' => [
				'toLower' => true,
			],
			'charEscaper' => true,
		],
	],
]);
```

Links
-----

[](#links)

- [Home page](https://code.divandesign.ru/modx/ddstringtools)
- [Telegram chat](https://t.me/dd_code)
- [Packagist](https://packagist.org/packages/dd/evolutioncms-snippets-ddstringtools)
- [GitHub](https://github.com/DivanDesign/EvolutionCMS.snippets.ddStringTools)

###  Health Score

31

—

LowBetter than 68% of packages

Maintenance46

Moderate activity, may be stable

Popularity2

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity60

Established project with proven stability

 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 ~199 days

Recently: every ~437 days

Total

11

Last Release

407d ago

Major Versions

1.7.0 → 2.0.02021-04-14

PHP version history (2 changes)1.4PHP &gt;=5.4.0

2.0.0PHP &gt;=5.6.0

### Community

Maintainers

![](https://www.gravatar.com/avatar/09b81986267e62b5fde1473b40aa6f11f7bc26c1c29d5f80f2768c8788e08110?d=identicon)[dd](/maintainers/dd)

---

Top Contributors

[![Ronef](https://avatars.githubusercontent.com/u/1333424?v=4)](https://github.com/Ronef "Ronef (97 commits)")

---

Tags

modxMODX Evomarkdownstringsevotypographytypographstrip\_tagsurl-encodeevolution-cmsmodx evolutionevo cmsddstringtoolsparse markdownhtml special charsescape for jsjs escaping

### Embed Badge

![Health badge](/badges/dd-evolutioncms-snippets-ddstringtools/health.svg)

```
[![Health](https://phpackages.com/badges/dd-evolutioncms-snippets-ddstringtools/health.svg)](https://phpackages.com/packages/dd-evolutioncms-snippets-ddstringtools)
```

PHPackages © 2026

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