|
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 |
pixelup Smarty n00b
Joined: 11 Apr 2017 Posts: 4
|
Posted: Tue Apr 11, 2017 10:34 am Post subject: function "substr" |
|
|
Hello,
I encountered a problem with the "substr:" function.
I want to use this function to delete the last character of the string.
Here is how I write my variable:
Code: | {capture assign="loop_moderators"}
{foreach name=moderators from = $session.programme_moderators item=moderator}
{$moderateur.formatage_programme},
{/foreach}
{/capture}
{$loop_moderators|substr:0:-1}
|
When I test, the last character is not deleted ??
Would you see why it does not work?
Thank you for your help |
|
Back to top |
|
AnrDaemon Administrator
Joined: 03 Dec 2012 Posts: 1785
|
Posted: Tue Apr 11, 2017 2:08 pm Post subject: |
|
|
{$loop_moderators|bin2hex}
{$loop_moderators|substr:0:-1|bin2hex} |
|
Back to top |
|
pixelup Smarty n00b
Joined: 11 Apr 2017 Posts: 4
|
Posted: Wed Apr 12, 2017 9:07 am Post subject: |
|
|
Thank you for reply but it does not work ! |
|
Back to top |
|
AnrDaemon Administrator
Joined: 03 Dec 2012 Posts: 1785
|
Posted: Wed Apr 12, 2017 10:40 am Post subject: |
|
|
"It doesn't work" is a ridiculous statement. It conveys essentially no information.
Please state clearly, what you are doing, what results you expect, and what you actually observe. |
|
Back to top |
|
pixelup Smarty n00b
Joined: 11 Apr 2017 Posts: 4
|
Posted: Wed Apr 12, 2017 12:36 pm Post subject: |
|
|
Ok sorry for that answer!
Here are more details:
Currently the result of this variable "{$ loop_moderators | substr: 0: -1}" is:
Quote: | P. Coulom (Toulouse / FRANCE), C. Silvain (Poitiers / FRANCE), P. Seksik (Paris / FRANCE) |
The last character is not deleted because the last character is the "comma"
With your variable "{$ loop_moderators | bin2hex}" or "{$ loop_moderators | substr: 0: -1 | bin2hex}" here is the result:
Quote: | {$ Loop_moderators | bin2hex}
...292c0a090909090909090909
|
Quote: | {$loop_moderators|substr:0:-1|bin2hex}
...292c0a0909090909090909 |
To recall here is the loop that I use to display the data of my variable
Code: | {capture assign="loop_moderators"}
{foreach name=moderators from = $session.programme_moderators item=moderators}
{$moderateur.formatage_programme},
{/foreach}
{/capture} |
Thanks |
|
Back to top |
|
AnrDaemon Administrator
Joined: 03 Dec 2012 Posts: 1785
|
Posted: Wed Apr 12, 2017 3:26 pm Post subject: |
|
|
pixelup wrote: | Quote: | {$ Loop_moderators | bin2hex}
...292c0a090909090909090909
|
Quote: | {$loop_moderators|substr:0:-1|bin2hex}
...292c0a0909090909090909 |
|
Sooo... evidently, the code works as intended. It properly strips the last character off the provided string.
Your problem is that your source data is full of whitespaces. Either provide a clean source data, or change code logic to remove unnecessary whitespaces. |
|
Back to top |
|
pixelup Smarty n00b
Joined: 11 Apr 2017 Posts: 4
|
Posted: Wed Apr 12, 2017 7:56 pm Post subject: |
|
|
Ok, thanks so much for your help!
I will examine more closely this history of space
And sorry for my english but I use google translate
thank you |
|
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
|