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
Post a Comment