如何将数组的这一元素转换为 utf-8?

发布于 2024-10-24 01:55:36 字数 901 浏览 3 评论 0原文

使用 Zend _gdata。由于某种原因,最近 $when 字符串不再是 utf-8。我需要将其转换为utf-8。所有其他领域都运行良好。

   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>';
   }

如何使 $when 为 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!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

权谋诡计 2024-10-31 01:55:36

根据该字符串使用的编码,您应该能够使用以下函数之一将其编码为 UTF-8:

例如:

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

或:

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

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']);
递刀给你 2024-10-31 01:55:36

如果字符串是 Latin1,您可以按照 Pascal 的建议进行操作。

否则你需要找出它是什么编码。
因此,请检查您的 php.ini 设置,或者您可以尝试通过 mb_detect_encoding 来检测它(请注意,这不是失败证明)

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)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文