Warning: strlen() expects parameter 1 to be string, array given in drupal_validate_utf8() I have been getting this error: Warning: strlen() expects parameter 1 to be string, array given in drupal_validate_utf8().



After troubleshooting I was able to figure out line that cause this error that is on a if stament. 

  if (empty ($form_state['num_boxes'])) { // Line with the problem.
    $form_state['num_boxes'] = count($boxes) + 1;
  }


After researching I believe that have to deal something with filter_xss_admin. However, it seem unclear to me of how to implement with my code.

Update 1 - Apparently, the code that I provide did not show the error. I have provide more code.



/**
 * Form builder.
 */
function custom_module_overview_form($form, &amp;$form_state) {

  $form['#tree'] = TRUE;
  $boxes = variable_get('custom_module_package_sizes', '');
  if (empty($form_state['num_boxes'])) {
    $form_state['num_boxes'] = count($boxes) + 1;
  }

  $form['sizes']['#prefix'] = '&lt;div id="boxes-fieldset-wrapper"&gt;';
  $form['sizes']['#suffix'] = '&lt;/div&gt;';

  for ($i = 0; $i &lt; $form_state['num_boxes']; $i++) {
    $form['sizes'][$i] = array(
      '#type' =&gt; 'fieldset',
      '#title' =&gt; t('Package'),
      '#description' =&gt; t('Enter the dimensions of the packing box.'),
      '#attributes' =&gt; array('class' =&gt; array('physical-dimensions-textfields')),
      '#attached' =&gt; array('css' =&gt; array(drupal_get_path('module', 'physical') . '/theme/physical.css')),
    );

    foreach (physical_dimensions() as $key =&gt; $dimension) {
      $form['sizes'][$i][$key] = array(
        '#type' =&gt; 'textfield',
        '#title' =&gt; filter_xss($dimension)['name'],
        '#size' =&gt; 15,
        '#maxlength' =&gt; 16,
        '#field_suffix' =&gt; '&amp;times;',
        '#prefix' =&gt; '&lt;div class="physical-dimension-form-item"&gt;',
        '#suffix' =&gt; '&lt;/div&gt;',
      );

      if (isset($boxes[$i][$key])) {
        $form['sizes'][$i][$key]['#default_value'] = $boxes[$i][$key];
      }
    }
    unset($form['sizes'][$i][$key]['#field_suffix']);

    $form['sizes'][$i]['unit'] = array(
      '#type' =&gt; 'select',
      '#options' =&gt; physical_dimension_unit_options(FALSE),
      '#prefix' =&gt; '&lt;div class="physical-dimensions-unit-form-item"&gt;',
      '#suffix' =&gt; '&lt;/div&gt;',
    );

    if (isset($boxes[$i]['unit'])) {
      $form['sizes'][$i]['unit']['#default_value'] = $boxes[$i]['unit'];
    }
  }

  $form['packing_add_more'] = array(
    '#type' =&gt; 'submit',
    '#value' =&gt; t('Add More'),
    '#prefix' =&gt; '&lt;div class="packing-add-more"&gt;',
    '#suffix' =&gt; '&lt;/div&gt;',
    '#submit' =&gt; array('custom_module_admin_add_more_submit'),
    '#ajax' =&gt; array(
      'callback' =&gt; 'custom_module_admin_add_more',
      'wrapper' =&gt; 'boxes-fieldset-wrapper',
    ),
  );

  $form['packing_submit'] = array(
    '#type' =&gt; 'submit',
    '#prefix' =&gt; '&lt;div class="packing-submit-save"&gt;',
    '#suffix' =&gt; '&lt;/div&gt;',
    '#value' =&gt; t('Save'),
  );

  drupal_add_library('system', 'drupal.ajax');

  return $form;
}


Update 2 - I believe that the issue is in this block

foreach (physical_dimensions() as $key =&gt; $dimension) {
          $form['sizes'][$i][$key] = array(
            '#type' =&gt; 'textfield',
            '#title' =&gt; filter_xss($dimension)['name'], // Removing this line would make the page disappears.
            '#size' =&gt; 15,
            '#maxlength' =&gt; 16,
            '#field_suffix' =&gt; '&amp;times;',
            '#prefix' =&gt; '&lt;div class="physical-dimension-form-item"&gt;',
            '#suffix' =&gt; '&lt;/div&gt;',
          );


On the line '#title' =&gt; filter_xss($dimension)['name'],

How can I fix this issue ?
To solve this issue I had to change this line  '#title' =&gt; filter_xss($dimension)['name'], to this On the line '#title' =&gt; filter_xss($dimension['name']),