This question already has an answer here:
How to process twig array?
(1 answer)
Closed 5 years ago.
I have an array serialized with php, and i would like to us it in a twig template. I tried the reverse filter but it doesn't work.
a:3:{i:1;a:2:{s:10:"mensualite";s:4:"1500";s:4:"date";s:10:"01/01/2018";}i:2;a:2:{s:10:"mensualite";s:4:"2500";s:4:"date";s:10:"02/01/2018";}i:3;a:2:{s:10:"mensualite";s:4:"3500";s:4:"date";s:10:"03/01/2018";}}
I did it in the controller
foreach($entity_partiellement as $ent ){
if(!empty($ent->getMensualite())){
$serial = unserialize($ent->getMensualite());
$ent->setMensualite($serial);
}
}
It's not very clean but it works
Related
This question already has answers here:
What kind of string is this? How do I unserialize this string? [duplicate]
(2 answers)
Closed 6 years ago.
This is a dump of row from postmeta table in wordpress database
How to parse this data out side of wordpress.
a:17:{s:13:"pa_tea-coffee";a:6:{s:4:"name";s:13:"pa_tea-coffee";s:5:"value";s:0:"";s:8:"position";s:1:"0";s:10:"is_visible";i:1;s:12:"is_variation";i:0;s:11:"is_taxonomy";i:1;}s:24:"pa_bottled-mineral-water";a:6:{s:4:"name";s:24:"pa_bottled-mineral-water";s:5:"value";s:0:"";s:8:"position";s:1:"1";s:10:"is_visible";i:1;s:12:"is_variation";i:0;s:11:"is_taxonomy";i:1;}s:17:"pa_drinking-water";a:6:{s:4:"name";s:17:"pa_drinking-water";s:5:"value";s:0:"";s:8:"position";s:1:"2";s:10:"is_visible";i:1;s:12:"is_variation";i:0;s:11:"is_taxonomy";i:1;}s:8:"pa_wi-fi";a:6:{s:4:"name";s:8:"pa_wi-fi";s:5:"value";s:0:"";s:8:"position";s:1:"3";s:10:"is_visible";i:1;s:12:"is_variation";i:0;s:11:"is_taxonomy";i:1;}s:7:"pa_cctv";a:6:{s:4:"name";s:7:"pa_cctv";s:5:"value";s:0:"";s:8:"position";s:1:"4";s:10:"is_visible";i:1;s:12:"is_variation";i:0;s:11:"is_taxonomy";i:1;}s:20:"pa_security-services";a:6:{s:4:"name";s:20:"pa_security-services";s:5:"value";s:0:"";s:8:"position";s:1:"5";s:10:"is_visible";i:1;s:12:"is_variation";i:0;s:11:"is_taxonomy";i:1;}s:27:"pa_fire_fighting_equipmment";a:6:{s:4:"name";s:27:"pa_fire_fighting_equipmment";s:5:"value";s:0:"";s:8:"position";s:1:"6";s:10:"is_visible";i:1;s:12:"is_variation";i:0;s:11:"is_taxonomy";i:1;}s:25:"pa_fire-alarms-sprinklers";a:6:{s:4:"name";s:25:"pa_fire-alarms-sprinklers";s:5:"value";s:0:"";s:8:"position";s:1:"7";s:10:"is_visible";i:1;s:12:"is_variation";i:0;s:11:"is_taxonomy";i:1;}s:21:"pa_reception-services";a:6:{s:4:"name";s:21:"pa_reception-services";s:5:"value";s:0:"";s:8:"position";s:1:"8";s:10:"is_visible";i:1;s:12:"is_variation";i:0;s:11:"is_taxonomy";i:1;}s:24:"pa_housekeeping-services";a:6:{s:4:"name";s:24:"pa_housekeeping-services";s:5:"value";s:0:"";s:8:"position";s:1:"9";s:10:"is_visible";i:1;s:12:"is_variation";i:0;s:11:"is_taxonomy";i:1;}s:17:"pa_centralized-ac";a:6:{s:4:"name";s:17:"pa_centralized-ac";s:5:"value";s:0:"";s:8:"position";s:2:"10";s:10:"is_visible";i:1;s:12:"is_variation";i:0;s:11:"is_taxonomy";i:1;}s:23:"pa_multiple-powerpoints";a:6:{s:4:"name";s:23:"pa_multiple-powerpoints";s:5:"value";s:0:"";s:8:"position";s:2:"11";s:10:"is_visible";i:1;s:12:"is_variation";i:0;s:11:"is_taxonomy";i:1;}s:23:"pa_train-station-access";a:6:{s:4:"name";s:23:"pa_train-station-access";s:5:"value";s:0:"";s:8:"position";s:2:"12";s:10:"is_visible";i:1;s:12:"is_variation";i:0;s:11:"is_taxonomy";i:1;}s:14:"pa_ups-back-up";a:6:{s:4:"name";s:14:"pa_ups-back-up";s:5:"value";s:0:"";s:8:"position";s:2:"13";s:10:"is_visible";i:1;s:12:"is_variation";i:0;s:11:"is_taxonomy";i:1;}s:20:"pa_4-wheeler-parking";a:6:{s:4:"name";s:20:"pa_4-wheeler-parking";s:5:"value";s:0:"";s:8:"position";s:2:"14";s:10:"is_visible";i:1;s:12:"is_variation";i:0;s:11:"is_taxonomy";i:1;}s:20:"pa_2-wheeler-parking";a:6:{s:4:"name";s:20:"pa_2-wheeler-parking";s:5:"value";s:0:"";s:8:"position";s:2:"15";s:10:"is_visible";i:1;s:12:"is_variation";i:0;s:11:"is_taxonomy";i:1;}s:17:"pa_public-parking";a:6:{s:4:"name";s:17:"pa_public-parking";s:5:"value";s:0:"";s:8:"position";s:2:"16";s:10:"is_visible";i:1;s:12:"is_variation";i:0;s:11:"is_taxonomy";i:1;}}
Save it to a variable and than use PHP's unserialze() function
$test = 'a:17:{s:13:"pa_tea-coffee";a:6:{s:4:"name";s:13:"pa_tea-coffee";s:5:"value";s:0:"";s:8:"position";s:1:"0";s:10:"is_visible";i:1;s:12:"is_variation";i:0;s:11:"is_taxonomy";i:1;}s:24:"pa_bottled-mineral-water";a:6:{s:4:"name";s:24:"pa_bottled-mineral-water";s:5:"value";s:0:"";s:8:"position";s:1:"1";s:10:"is_visible";i:1;s:12:"is_variation";i:0;s:11:"is_taxonomy";i:1;}s:17:"pa_drinking-water";a:6:{s:4:"name";s:17:"pa_drinking-water";s:5:"value";s:0:"";s:8:"position";s:1:"2";s:10:"is_visible";i:1;s:12:"is_variation";i:0;s:11:"is_taxonomy";i:1;}s:8:"pa_wi-fi";a:6:{s:4:"name";s:8:"pa_wi-fi";s:5:"value";s:0:"";s:8:"position";s:1:"3";s:10:"is_visible";i:1;s:12:"is_variation";i:0;s:11:"is_taxonomy";i:1;}s:7:"pa_cctv";a:6:{s:4:"name";s:7:"pa_cctv";s:5:"value";s:0:"";s:8:"position";s:1:"4";s:10:"is_visible";i:1;s:12:"is_variation";i:0;s:11:"is_taxonomy";i:1;}s:20:"pa_security-services";a:6:{s:4:"name";s:20:"pa_security-services";s:5:"value";s:0:"";s:8:"position";s:1:"5";s:10:"is_visible";i:1;s:12:"is_variation";i:0;s:11:"is_taxonomy";i:1;}s:27:"pa_fire_fighting_equipmment";a:6:{s:4:"name";s:27:"pa_fire_fighting_equipmment";s:5:"value";s:0:"";s:8:"position";s:1:"6";s:10:"is_visible";i:1;s:12:"is_variation";i:0;s:11:"is_taxonomy";i:1;}s:25:"pa_fire-alarms-sprinklers";a:6:{s:4:"name";s:25:"pa_fire-alarms-sprinklers";s:5:"value";s:0:"";s:8:"position";s:1:"7";s:10:"is_visible";i:1;s:12:"is_variation";i:0;s:11:"is_taxonomy";i:1;}s:21:"pa_reception-services";a:6:{s:4:"name";s:21:"pa_reception-services";s:5:"value";s:0:"";s:8:"position";s:1:"8";s:10:"is_visible";i:1;s:12:"is_variation";i:0;s:11:"is_taxonomy";i:1;}s:24:"pa_housekeeping-services";a:6:{s:4:"name";s:24:"pa_housekeeping-services";s:5:"value";s:0:"";s:8:"position";s:1:"9";s:10:"is_visible";i:1;s:12:"is_variation";i:0;s:11:"is_taxonomy";i:1;}s:17:"pa_centralized-ac";a:6:{s:4:"name";s:17:"pa_centralized-ac";s:5:"value";s:0:"";s:8:"position";s:2:"10";s:10:"is_visible";i:1;s:12:"is_variation";i:0;s:11:"is_taxonomy";i:1;}s:23:"pa_multiple-powerpoints";a:6:{s:4:"name";s:23:"pa_multiple-powerpoints";s:5:"value";s:0:"";s:8:"position";s:2:"11";s:10:"is_visible";i:1;s:12:"is_variation";i:0;s:11:"is_taxonomy";i:1;}s:23:"pa_train-station-access";a:6:{s:4:"name";s:23:"pa_train-station-access";s:5:"value";s:0:"";s:8:"position";s:2:"12";s:10:"is_visible";i:1;s:12:"is_variation";i:0;s:11:"is_taxonomy";i:1;}s:14:"pa_ups-back-up";a:6:{s:4:"name";s:14:"pa_ups-back-up";s:5:"value";s:0:"";s:8:"position";s:2:"13";s:10:"is_visible";i:1;s:12:"is_variation";i:0;s:11:"is_taxonomy";i:1;}s:20:"pa_4-wheeler-parking";a:6:{s:4:"name";s:20:"pa_4-wheeler-parking";s:5:"value";s:0:"";s:8:"position";s:2:"14";s:10:"is_visible";i:1;s:12:"is_variation";i:0;s:11:"is_taxonomy";i:1;}s:20:"pa_2-wheeler-parking";a:6:{s:4:"name";s:20:"pa_2-wheeler-parking";s:5:"value";s:0:"";s:8:"position";s:2:"15";s:10:"is_visible";i:1;s:12:"is_variation";i:0;s:11:"is_taxonomy";i:1;}s:17:"pa_public-parking";a:6:{s:4:"name";s:17:"pa_public-parking";s:5:"value";s:0:"";s:8:"position";s:2:"16";s:10:"is_visible";i:1;s:12:"is_variation";i:0;s:11:"is_taxonomy";i:1;}}';
$result = unserialize($test);
print_r($result);
This question already has answers here:
What kind of string is this? How do I unserialize this string? [duplicate]
(2 answers)
Closed 6 years ago.
I got the following string:
a:16:{i:0;s:1:"6";i:1;s:2:"12";i:2;s:1:"2";i:3;s:2:"11";i:4;s:1:"7";i:5;s:2:"10";i:6;s:2:"16";i:7;s:1:"5";i:8;s:1:"3";i:9;s:1:"1";i:10;s:2:"14";i:11;s:1:"8";i:12;s:2:"13";i:13;s:1:"9";i:14;s:1:"4";i:15;s:2:"15";}
I can't use
var_dump(json_decode($json))
because it doesn't return anything. I found 2 websites that where a bit usefull:
http://jsonlint.com/ for checking if the object is valid (what it ain't) and http://www.unserialize.com/ wich can 'unserialize' the json string back to an array.
Now I wonder what unserialize does to the json string. So I can use it in my script as well.
Looks like this is in serialized form. You need to use unserialize() function here.
$input = 'a:16:{i:0;s:1:"6";i:1;s:2:"12";i:2;s:1:"2";i:3;s:2:"11";i:4;s:1:"7";i:5;s:2:"10";i:6;s:2:"16";i:7;s:1:"5";i:8;s:1:"3";i:9;s:1:"1";i:10;s:2:"14";i:11;s:1:"8";i:12;s:2:"13";i:13;s:1:"9";i:14;s:1:"4";i:15;s:2:"15";}';
var_dump(unserialize($input));
Use unserialize function in php
<?php
echo '<pre>';
print_r(unserialize('a:16:{i:0;s:1:"6";i:1;s:2:"12";i:2;s:1:"2";i:3;s:2:"11";i:4;s:1:"7";i:5;s:2:"10";i:6;s:2:"16";i:7;s:1:"5";i:8;s:1:"3";i:9;s:1:"1";i:10;s:2:"14";i:11;s:1:"8";i:12;s:2:"13";i:13;s:1:"9";i:14;s:1:"4";i:15;s:2:"15";}'));
?>
https://eval.in/637790
This question already has answers here:
What kind of string is this? How do I unserialize this string? [duplicate]
(2 answers)
Closed 6 years ago.
I receive a really long json array like following:
a:2:{s:18:"_gravity_form_lead";a:227:{s:3:"3.2";s:0:"";s:3:"3.3";s:5:"Name";s:3:"3.4";s:0:"";s:3:"3.6";s:1:"T";s:3:"3.8";s:0:"";i:4;s:14:"123456789-3505";i:6;s:0:"";s:3:"7.1";s:0:"";s:3:"9.2";s:0:"";s:3:"9.3";s:0:"";s:3:"9.4";s:0:"";s:3:"9.6";s:0:"";s:3:"9.8";s:0:"";i:12;s:0:"";i:10;s:0:"";i:11;s:0:"";s:4:"13.1";s:0:"";s:4:"13.2";s:0:"";s:4:"13.3";s:0:"";s:4:"13.4";s:0:"";s:4:"13.5";s:0:"";s:4:"13.6";s:0:"";i:14;s:0:"";i:15;s:0:"";i:16;s:0:"";i:84;s:0:"";i:85;s:0:"";i:18;s:0:"";i:19;s:0:"";i:20;s:0:"";i:21;s:0:"";i:22;s:0:"";i:88;s:0:"";i:89;s:0:"";i:90;s:0:"";i:91;s:0:"";i:92;s:0:"";i:93;s:0:"";i:94;s:0:"";i:96;s:0:"";i:97;s:0:"";i:98;s:0:"";i:102;s:0:"";i:99;s:0:"";i:100;s:0:"";i:101;s:0:"";i:104;s:0:"";i:105;s:0:"";i:106;s:0:"";i:107;s:0:"";i:108;s:0:"";i:109;s:0:"";i:110;s:0:"";i:112;s:0:"";i:113;s:0:"";i:114;s:0:"";i:115;s:0:"";i:116;s:0:"";i:117;s:0:"";i:118;s:0:"";s:4:"28.1";s:0:"";s:4:"28.2";s:0:"";s:4:"28.3";s:0:"";s:4:"28.4";s:0:"";s:4:"28.5";s:0:"";s:4:"28.6";s:0:"";i:29;s:0:"";i:30;s:0:"";s:4:"33.1";s:0:"";s:4:"33.2";s:0:"";s:4:"33.3";s:0:"";s:4:"33.4";s:0:"";s:4:"33.5";s:0:"";s:4:"33.6";s:0:"";i:35;s:0:"";i:36;s:0:"";i:37;s:0:"";i:38;s:0:"";i:41;s:0:"";s:4:"39.1";s:0:"";s:4:"39.2";s:0:"";s:4:"39.3";s:0:"";s:4:"39.4";s:0:"";s:4:"39.5";s:0:"";s:4:"39.6";s:0:"";i:121;s:0:"";i:122;s:0:"";i:123;s:0:"";i:124;s:0:"";i:126;s:0:"";s:5:"125.1";s:0:"";s:5:"125.2";s:0:"";s:5:"125.3";s:0:"";s:5:"125.4";s:0:"";s:5:"125.5";s:0:"";s:5:"125.6";s:0:"";i:128;s:0:"";i:129;s:0:"";i:130;s:0:"";i:131;s:0:"";i:132;s:0:"";s:5:"133.1";s:0:"";s:5:"133.2";s:0:"";s:5:"133.3";s:0:"";s:5:"133.4";s:0:"";s:5:"133.5";s:0:"";s:5:"133.6";s:0:"";i:135;s:0:"";i:136;s:0:"";i:137;s:0:"";i:138;s:0:"";i:139;s:0:"";s:5:"140.1";s:0:"";s:5:"140.2";s:0:"";s:5:"140.3";s:0:"";s:5:"140.4";s:0:"";s:5:"140.5";s:0:"";s:5:"140.6";s:0:"";i:142;s:0:"";i:143;s:0:"";i:144;s:0:"";i:145;s:0:"";i:146;s:0:"";i:149;s:0:"";i:150;s:0:"";i:151;s:0:"";i:152;s:0:"";i:153;s:0:"";s:5:"147.1";s:0:"";s:5:"147.2";s:0:"";s:5:"147.3";s:0:"";s:5:"147.4";s:0:"";s:5:"147.5";s:0:"";s:5:"147.6";s:0:"";i:155;s:0:"";i:156;s:0:"";i:157;s:0:"";i:158;s:0:"";i:159;s:0:"";s:5:"160.1";s:0:"";s:5:"160.2";s:0:"";s:5:"160.3";s:0:"";s:5:"160.4";s:0:"";s:5:"160.5";s:0:"";s:5:"160.6";s:0:"";i:162;s:0:"";i:163;s:0:"";i:164;s:0:"";i:165;s:0:"";i:166;s:0:"";s:5:"167.1";s:0:"";s:5:"167.2";s:0:"";s:5:"167.3";s:0:"";s:5:"167.4";s:0:"";s:5:"167.5";s:0:"";s:5:"167.6";s:0:"";i:169;s:0:"";i:170;s:0:"";i:171;s:0:"";i:172;s:0:"";i:173;s:0:"";s:5:"174.1";s:0:"";s:5:"174.2";s:0:"";s:5:"174.3";s:0:"";s:5:"174.4";s:0:"";s:5:"174.5";s:0:"";s:5:"174.6";s:0:"";i:176;s:0:"";i:177;s:0:"";i:178;s:0:"";i:179;s:0:"";i:180;s:0:"";s:5:"181.1";s:0:"";s:5:"181.2";s:0:"";s:5:"181.3";s:0:"";s:5:"181.4";s:0:"";s:5:"181.5";s:0:"";s:5:"181.6";s:0:"";i:40;s:0:"";i:43;s:2:"Ne";i:184;s:0:"";i:185;s:0:"";i:48;s:0:"";i:187;s:0:"";i:188;s:0:"";i:189;s:0:"";i:191;s:0:"";i:192;s:0:"";i:193;s:0:"";i:195;s:0:"";i:196;s:0:"";i:197;s:0:"";i:199;s:0:"";i:200;s:0:"";i:201;s:0:"";i:44;s:0:"";i:45;s:0:"";i:50;s:2:"Ne";i:51;s:2:"Ne";i:52;s:2:"Ne";i:53;s:0:"";i:55;s:0:"";i:56;s:0:"";i:57;s:0:"";i:58;s:0:"";i:59;s:0:"";i:60;s:2:"Ne";i:61;s:2:"Ne";i:62;s:0:"";i:69;s:2:"Ne";i:70;s:0:"";i:71;s:0:"";i:72;s:0:"";i:77;s:0:"";i:78;s:0:"";i:79;s:0:"";i:80;s:0:"";i:81;s:0:"";i:203;s:0:"";i:204;s:27:"56f26f5862fb85.90873638.png";}s:18:"_gravity_form_data";a:14:{s:2:"id";s:1:"1";s:13:"display_title";b:0;s:19:"display_description";b:0;s:25:"disable_woocommerce_price";s:3:"yes";s:12:"price_before";s:0:"";s:11:"price_after";s:0:"";s:20:"disable_calculations";s:3:"yes";s:22:"disable_label_subtotal";s:3:"yes";s:21:"disable_label_options";s:2:"no";s:19:"disable_label_total";s:3:"yes";s:14:"disable_anchor";s:2:"no";s:14:"label_subtotal";s:8:"Subtotal";s:13:"label_options";s:7:"Options";s:11:"label_total";s:5:"Total";}}
I need to extract the name of the png which in this array is: 56f26f5862fb85.90873638.png. The value is the following context:
i:204;s:27:"56f26f5862fb85.90873638.png";
It would be really convenient if I could look the name after the 204 which is always fixec.
Any guidance or suggestion as for how to solve it is much appreciated.
That is a serialized PHP value, created using the serialize() function.
You can unserialize it using the unserialize() function:
$data = unserialize('a:2:{s:18:"_gravity [...] tal";s:5:"Total";}}');
This question already has answers here:
What is PHP's serialize() function for?
(4 answers)
Closed 9 years ago.
I come across that array-looking object in a php file. Any clue what it is and how it works?
a:1:{i:2;a:2:{i:0;s:1:"m";i:1;s:10:"2013-02-11";}}
What you have is a serialized string. Run it through unserialize to convert it into a usable format.
Replace $string in the example below.
$unserialized = unserialize( $string );
This question already has answers here:
A simple program to CRUD node and node values of xml file [closed]
(2 answers)
Closed 8 years ago.
Try this query:
http://www.dictionaryapi.com/api/v1/references/collegiate/xml/gobabola?key=135a6187-af83-4e85-85c1-1a28db11d5da
How do I simply read in the suggestions as variables? I can't seem to find anything that explains this.
You can use SimpleXmlIterator. That's really easy to use and you will be able to perform a foreach on the object you will get.
Library source
For example with file_get_contents or replace with curl if you prefer:
$feed = new SimpleXmlIterator(file_get_contents('http://www.dictionaryapi.com/api/v1/references/collegiate/xml/gobabola?key=135a6187-af83-4e85-85c1-1a28db11d5da'));
foreach ($feed->suggestion as $suggestion) {
echo $value;
}