开发者

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!


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

  • utf8_encode()
  • iconv()


For example :

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

Or :

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


If the string is in Latin1 you can just do what Pascal suggests.

Otherwise you need to find out which encoding it is. Therefor check your php.ini settings or you can try to detect it by mb_detect_encoding (be aware it's not fail prove)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜