PHP code example of dd / evolutioncms-snippets-ddstringtools

1. Go to this page and download the library: Download dd/evolutioncms-snippets-ddstringtools library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

dd / evolutioncms-snippets-ddstringtools example snippets


//Include (MODX)EvolutionCMS.libraries.ddInstaller
nstaller/Installer::install([
	'url' => 'https://github.com/DivanDesign/EvolutionCMS.snippets.ddStringTools',
	'type' => 'snippet'
]);

$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
		]
	]
);

//Include (MODX)EvolutionCMS.libraries.ddTools
/ddTools/modx.ddtools.class.php'
);

//Run (MODX)EvolutionCMS.snippets.ddStringTools
\DDTools\Snippet::runSnippet([
	'name' => 'ddStringTools',
	'params' => [
		'inputString' => '<div class="someTrash"></div><p><b>Some</b> <a href="#">sample</a> <i>text</i>. [+somePlaceholder+]</p>.',
		//`tools` in this case can be set as a native PHP array or object
		'tools' => [
			'placeholderRemover' => true,
			'typographer' => true,
			'tagRemover' => [
				'allowed' => '<p><a>'
			],
			'caseConverter' => [
				'toLower' => true
			],
			'charEscaper' => true
		]
	]
]);
html
[[ddStringTools?
	&inputString=`<div class="someTrash"></div><p><b>Some</b> <a href="#">sample</a> <i>text</i>.</p>`
	&tools=`{
		"tagRemover": true
	}`
]]
html
[[ddStringTools?
	&inputString=`<div class="someTrash"></div><p><b>Some</b> <a href="#">sample</a> <i>text</i>.</p>`
	&tools=`{
		"tagRemover": {
			"allowed": "<p><a>"
		}
	}`
]]
html
[[ddStringTools?
	&inputString=`<p>Some <a href="#">sample</a> text.</p>`
	&tools=`{
		"specialCharConverter": true
	}`
]]
html
[[ddStringTools?
	&inputString=`<p>Some text containing "quoted" text.</p>`
	&tools=`{
		"typographer": {
			"optAlign": true
		}
	}`
]]
html
[[ddStringTools?
	&inputString=`Some text for typography.`
	&tools=`{
		"typographer": true
	}`
]]
html
[[ddStringTools?
	&inputString=`<div class="someTrash"></div><p><b>Some</b> <a href="#">sample</a> <i>text</i>. [+somePlaceholder+]</p>.`
	&tools=`{
		"placeholderRemover": true,
		"typographer": true,
		"tagRemover": {
			"allowed": "<p><a>"
		},
		"caseConverter": {
			"toLower": true
		},
		"charEscaper": true
	}`
]]