|
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 |
strandkorbprofi Smarty n00b
Joined: 16 Oct 2018 Posts: 2
|
Posted: Tue Oct 16, 2018 12:16 pm Post subject: long string - how to read certain parts of it |
|
|
Hello everybody,
my first post and my first problem.
I've this variable Code: | {$details.ob_emo_areacalculator} | , that contains a long string:
Code: | {"articlenumber":71390,"baseprice":55,"totalprice":55,"length":100,"width":100,"totalarea":"1,00","lenwid_unit":"cm","area_unit":"m²"} |
That's a wierd string - it seems to contain even the brackets.
Now I would like to read just two parts out of this string:
length: 100
width: 100
I'm new to smarty, but have some basic coding-skills. I really would like to dig deeper into smarty (and will do it), but at the moment I'm running out of time and I would be very glad about a hint how to do this in smarty.
Cheers,
Arne |
|
Back to top |
|
strandkorbprofi Smarty n00b
Joined: 16 Oct 2018 Posts: 2
|
Posted: Tue Oct 16, 2018 1:44 pm Post subject: |
|
|
OK, here's a solution:
Code: | {assign var="areacalculatorArray" value=","|explode:$details.ob_emo_areacalculator}
{$areacalculatorArray[3]|replace:'"length"':"Länge"}cm<br/>
{$areacalculatorArray[4]|replace:'"width"':"Breite"}cm
|
Output
Länge:100cm
Breite:100cm |
|
Back to top |
|
AnrDaemon Administrator
Joined: 03 Dec 2012 Posts: 1785
|
Posted: Tue Oct 16, 2018 2:37 pm Post subject: |
|
|
That "long string" is a JSON encoded data blob.
You can use json_decode to turn it into an array. |
|
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
|