0

When I select the extra field of a webform component:

$webform_components = db_select('webform_component', 'c')
                          ->fields('c', array('type', 'form_key', 'extra'))
                          ->condition('nid', $nid)
                          ->execute()
                          ->fetchAll();

The extra field is something like this (the following example is a grid component):

"a:8:{s:13:\"title_display\";s:4:\"none\";s:7:\"private\";i:0;s:15:\"wrapper_classes\";s:0:\"\";s:6:\"sticky\";i:1;s:7:\"options\";s:20:\"5|poor\n10|excellent\n\";s:18:\"custom_option_keys\";i:1;s:9:\"questions\";s:159:\"mensaje|Each message is associated with a language, which may or may not be the\nactual|current user's selected language, depending on the type of e-mail being\n\";s:20:\"custom_question_keys\";i:1;}"

I want to get the options and the questions. In the previous example:

\"options\";s:20:\"5|poor\n10|excellent\

Option 1: 5 (key) | poor (value)

Option 2: 10 (key) | excellent (value)

\"questions\";s:159:\"mensaje|Each message is associated with a language, which may or may not be the\nactual|current user's selected language, depending on the type of e-mail being

Question 1: mensaje (key) | Each message [...] (value)

Question 2: actual (key)| current user's [...] (value)

I don't know how to process this extra string. I tried to transform it to an array and a json, but it didn't work.

Thank you for your help! :)

0

It's a serialised PHP string, so:

$unserialised = unserialize($input);

// Split $unserialised['options'] by the '|' char, then extract keys/values
  • I love you so much! :* I didn't know this string type. BTW, there is a typo in the function name, is unserialize (I'm newbie, sorry I cannot edit automatically your answer). – ecurbelo Sep 4 '15 at 13:09
  • Happy to help :) Sorry 'bout the typo (the pains of speaking British English and using a language predominantly written by American English speakers!) I've fixed that now – Clive Sep 4 '15 at 13:12

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.