0

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!

Charles
  • 50,943
  • 13
  • 104
  • 142
Joel
  • 2,691
  • 7
  • 40
  • 72

2 Answers2

4

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']);
Pascal MARTIN
  • 395,085
  • 80
  • 655
  • 663
  • Well this issue is really weird. I'm seing I guess it's not a unicode issue. If you look here http://rattletree.com/upcomingshows2.php You can see in the first column the Month name is getting all screwed up. But using mb_detect_encoding, it is telling me its utf-8. – Joel Mar 19 '11 at 21:32
  • This is a bummer. It was working a week ago and now this. I have no idea how to even address this problem :( – Joel Mar 19 '11 at 21:40
  • Well I did find this thread-looks like it's a google issue http://www.google.com/support/forum/p/Calendar/thread?tid=25ac3d762b235a51&hl=en – Joel Mar 19 '11 at 21:54
  • Oh, nice :-) maybe the `hl=en` solution will work for you too ? – Pascal MARTIN Mar 19 '11 at 21:59
  • I hope so. I need to figure out how to append that since I am retrieving the feed as an object. I'll post a new question. Thanks for your help. – Joel Mar 20 '11 at 05:27
1

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)

Min
  • 31
  • 2