php - preg_replace not working in snippet -


i tying use following modx evo snippet (naming "removespace") output tv removing space in string:

<?php $string1 = "[*longtitle*]";  $string = preg_replace('/\s+/', '', $string1); return $string; ?> 

but calling snippet [[removespace]] in template not produce string space removed. produces string is.

but inserting text "hello world" in $string1 variable produces result without space.

any solution?

you can not use modx tags inside snippets, need use $modx->documentobject['variable-name']

so code this:

<?php $string1 = $modx->documentobject['longtitle'];  $string = preg_replace('/\s+/', '', $string1); return $string; ?> 

Comments

Popular posts from this blog

powershell Start-Process exit code -1073741502 when used with Credential from a windows service environment -

twig - Using Twigbridge in a Laravel 5.1 Package -

c# - LINQ join Entities from HashSet's, Join vs Dictionary vs HashSet performance -