|
Smarty
WARNING: All discussion is moving to https://reddit.com/r/smarty, please go there! This forum will be closing soon. |
|
View previous topic :: View next topic |
Author |
Message |
jeteon Smarty n00b
Joined: 07 Oct 2015 Posts: 2
|
Posted: Wed Oct 07, 2015 6:46 pm Post subject: Smarty uses preg_replace incorrectly |
|
|
I'm posting this here because the issue tracker on Google code is no longer operational due to Google code being shut down.
I am using Smarty 3.1 with PHP 5.5.9 on an i386 machine running Ubuntu 14.04. When I used the smarty preg_replace() function, code that has the pattern:
Code: |
{$variable | preg_replace:"/(?i)<br\s*\/?>/":" "}
|
is translated to something like:
Code: |
<?php echo preg_replace(
$_smarty_tpl->tpl_vars['variable'],
"/(?i)<br\s*\/?>/",
" "
);?>
|
According to the PHP documentation, the regexp comes first and the text itself last, instead of the order that is created by Smarty.
jeteon |
|
Back to top |
|
AnrDaemon Administrator
Joined: 03 Dec 2012 Posts: 1785
|
Posted: Wed Oct 07, 2015 9:30 pm Post subject: |
|
|
It is not Smarty, it is YOU using it incorrectly.
Correct use would be
{$pattern|preg_replace:$replacement:$variable} |
|
Back to top |
|
jeteon Smarty n00b
Joined: 07 Oct 2015 Posts: 2
|
Posted: Wed Oct 07, 2015 10:26 pm Post subject: |
|
|
You're right. I was looking up the syntax for regexp_replace in the docs and testing the regex using preg_replace on the command line. I guess at some point, I carried the function name over into my source. |
|
Back to top |
|
AnrDaemon Administrator
Joined: 03 Dec 2012 Posts: 1785
|
Posted: Thu Oct 08, 2015 11:05 am Post subject: |
|
|
Generally speaking, it is not nice to make complex changes to the passed data in such a way inside the template.
This makes debugging more complicated for the designer. |
|
Back to top |
|
U.Tews Administrator
Joined: 22 Nov 2006 Posts: 5068 Location: Hamburg / Germany
|
|
Back to top |
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|