dsj83686 2011-01-22 09:58
浏览 19
已采纳

Php - 从类中格式化双引号字符串

I have a class that build my main navigation. Everything works fine except for the html output i get in the source code. In my class i got something like this:

public function getNav(){
   $output = "";
   foreach($nav as $key=>$value){
       $output .= "<li><a href='$value'>$key</a></li>
";
   }
   return $output;
}

Then i show navigation in my template...

    <ul class="nav">
    <?php echo $site->getNav(); ?>
    </ul>

... and the html source look like this:

     <ul id="nav">
           <li><a href='index.php'><span>HOME</span></a></li>
<li><a href='page2.php'><span>PAGE 2</span></a></li>
<li><a href='page3.php'><span>PAGE 3</span></a></li>
     </ul>

This is probably irrelevant, i'm just trying to understand if i get this due to the double quoted or what...

  • 写回答

1条回答 默认 最新

  • doupao1978 2011-01-22 10:04
    关注

    This output has nothing to do with the doublequotes(except the linebreak, which you wouldn't have without them).

    Are you sure that your template is

        <ul class="nav">
        <?php echo $site->getNav(); ?>
        </ul>
    

    ...and not

        <ul class="nav">
              <?php echo $site->getNav(); ?>
        </ul>
    

    ? That's the only mysterious thing I see.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 在获取boss直聘的聊天的时候只能获取到前40条聊天数据
  • ¥20 关于URL获取的参数,无法执行二选一查询
  • ¥15 液位控制,当液位超过高限时常开触点59闭合,直到液位低于低限时,断开
  • ¥15 marlin编译错误,如何解决?
  • ¥15 有偿四位数,节约算法和扫描算法
  • ¥15 VUE项目怎么运行,系统打不开
  • ¥50 pointpillars等目标检测算法怎么融合注意力机制
  • ¥20 Vs code Mac系统 PHP Debug调试环境配置
  • ¥60 大一项目课,微信小程序
  • ¥15 求视频摘要youtube和ovp数据集