Search code examples
phpzend-frameworkutf-8zend-gdata

How do I convert this one element of the array to utf-8?


Using Zend _gdata. For some reason, recently the $when string is no longer utf-8. I need to convert it to utf-8. All the other fields are working fine.

   foreach ($feed as $event) { //iterating through all events

      $contentText = stripslashes($event->content->text); //striping any escape character
      $contentText = preg_replace('/\<br \/\>[\n\t\s]{1,}\<br \/\>/','<br />',stripslashes($event->content->text)); //replacing multiple breaks with a single break
      $contentText = explode('<br />',$contentText); //splitting data by break tag

      $eventData = filterEventDetails($contentText);
      $when = $eventData['when'];
      $where = $eventData['where'];
      $duration = $eventData['duration'];
      $title = stripslashes($event->title);
      echo '<li class="pastShows">' . $when . " - " . $title . ", " . $where . '</li>';
   }

How do I make $when utf-8? Thanks!


Solution

  • Depending on what encoding that string is using, you should be able to encode it to UTF-8 using one of the following functions :


    For example :

    $when = utf8_encode($eventData['when']);
    

    Or :

    $when = iconv('ISO-8859-1', 'UTF-8', $eventData['when']);