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

symfony - TEST environment only: The database schema is not in sync with the current mapping file -

twig - Using Twigbridge in a Laravel 5.1 Package -

jdbc - Not able to establish database connection in eclipse -