dpdfh60088 2011-05-04 17:47
浏览 46

strlen&special chars

I'm having an issue finding a solution here.. I'm developing a WordPress theme for a client that uses a for() loop to iterate through the title of the page so it can be wrapped in <span>s and displayed vertically.. the loop uses strlen() to find the length of the title but since some of the page titles include '...' or commas in the title it returns the html chars instead.. I can't figure out what is causing that and every effort via htmlspecialchars_decode() or html_entity_decode() doesn't work.. any suggestions? Is there something going on with the for loop that I'm now aware of?

Since it was requested here is the actual code:

$p_title = get_the_title($port_page->ID);
   $title = '';

   for($i=0;$i<strlen($p_title);$i++){
   if(($p_title[$i])){
     $title .="<span>$p_title[$i]</span>";
    }

I've tried using mb_strlen as well.. the problem with searching for a specific character to replace doesn't necessarily solve the problem since page titles are arbitrarily set by the site owner..

The weird thing is the Title is not encoded in any way and echo's normally before the for loop.. So it's as if something is converting it..

  • 写回答

2条回答 默认 最新

  • douweng1935 2011-05-04 17:50
    关注

    This sounds a lot like a character encoding issue with multibyte characters. Can you try replacing strlen() with mb_strlen() and see if it does the job?

    http://php.net/manual/en/function.mb-strlen.php

    评论

报告相同问题?

悬赏问题

  • ¥15 微信小程序协议怎么写
  • ¥15 c语言怎么用printf(“\b \b”)与getch()实现黑框里写入与删除?
  • ¥20 怎么用dlib库的算法识别小麦病虫害
  • ¥15 华为ensp模拟器中S5700交换机在配置过程中老是反复重启
  • ¥15 java写代码遇到问题,求帮助
  • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?
  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看