donglinxi1467 2012-02-22 13:35
浏览 11
已采纳

从数据库中“切断”HTML值然后在网站上输出

I'm storing an HTML values in my database then I output it on my site.
There was an HTML value that has a "cut off" HTML (I don't have control on the HTML, since I'm getting it on a different website" ), meaning to say, it looks like this

<a href="http://site.com

When I output this on my site I'm having a problem because below those "cut off" HTML, other HTML will be affected, so it looks like this (example)

<a href="http://site.com  <input type="button" value="test" />

My question here is that how would I know if an HTML is being cut off, then if it has been cut off, I want to close it by simple closing it with " or />

  • 写回答

2条回答 默认 最新

  • douzha6055 2012-02-22 13:54
    关注

    A way to see if it's cut off or not would be to look if the amount of <'s is the same as the amount of >'s. So like this:

    <?php
    list($len, $a, $b) = array(strlen($html), 0, 0);
    for ($i = 0; $i < $len; $char = $html[$i++]) {
        if ($char == '<')
            $a++;
        if ($char == '>')
            $b++;
    }
    $broken = true;
    if ($a == $b)
        $broken = false;
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 单片机学习顺序问题!!
  • ¥15 ikuai客户端多拨vpn,重启总是有个别重拨不上
  • ¥20 关于#anlogic#sdram#的问题,如何解决?(关键词-performance)
  • ¥15 相敏解调 matlab
  • ¥15 求lingo代码和思路
  • ¥15 公交车和无人机协同运输
  • ¥15 stm32代码移植没反应
  • ¥15 matlab基于pde算法图像修复,为什么只能对示例图像有效
  • ¥100 连续两帧图像高速减法
  • ¥15 如何绘制动力学系统的相图