1. 论坛系统升级为Xenforo,欢迎大家测试!
    Dismiss Notice

问一个 PHP 的问题

Discussion in '后端开发' started by 不学无术, Dec 4, 2008.

  1. 不学无术

    不学无术 Ulysses 的元神

    Joined:
    Aug 31, 2005
    Messages:
    16,714
    Likes Received:
    39
    有个数据表格如下:

    HTML:
    <table>
      <tr>
        <td><a href="xxx.html">文章标题</a></td>
        <td><a href="bbb.html">作者</a></td>
      </tr>
      <tr>
        <td><a href="xxx.html">文章标题</a></td>
        <td><a href="bbb.html">作者</a></td>
      </tr>
      <tr>
        <td><a href="xxx.html">文章标题</a></td>
        <td><a href="bbb.html">作者</a></td>
      </tr>
    </table>
    我想转换成如下的内容:

    HTML:
    <ul>
      <li><a href="xxx.html">文章标题</a> <a href="bbb.html">作者</a></li>
      <li><a href="xxx.html">文章标题</a> <a href="bbb.html">作者</a></li>
      <li><a href="xxx.html">文章标题</a> <a href="bbb.html">作者</a></li>
    </ul>

    有啥简单好用的方法呢?例如正则匹配?

    谢谢!
     
  2. apple

    apple New Member

    Joined:
    May 22, 2006
    Messages:
    9,561
    Likes Received:
    78
    HTML:
    <table>
      <tr>
        <td>
    <ul>
      <li><a href="xxx.html">文章标题</a> <a href="bbb.html">作者</a>< >
      <li><a href="xxx.html">文章标题</a> <a href="bbb.html">作者</a>< >
      <li><a href="xxx.html">文章标题</a> <a href="bbb.html">作者</a>< >
    </ul>
    </td>
      </tr>
    <table>
    
    直接这样换不行么?
     
  3. 不学无术

    不学无术 Ulysses 的元神

    Joined:
    Aug 31, 2005
    Messages:
    16,714
    Likes Received:
    39
    啊,不是这个意思。
     
  4. apple

    apple New Member

    Joined:
    May 22, 2006
    Messages:
    9,561
    Likes Received:
    78
    :sweat:又弄错了!
     
  5. A君

    A君 Well-Known Member

    Joined:
    Aug 31, 2005
    Messages:
    19,987
    Likes Received:
    98
    不懂,友情帮顶
     
  6. fyfei

    fyfei New Member

    Joined:
    Oct 7, 2005
    Messages:
    9,067
    Likes Received:
    46
    直接替换,见<table>换成ul
    见tr换成li
    然后替换td为空
     
  7. 不学无术

    不学无术 Ulysses 的元神

    Joined:
    Aug 31, 2005
    Messages:
    16,714
    Likes Received:
    39
    牛人,我太崇拜你了!

    其实实际情况比这个复杂呀。而且我也想学学如何从 HTML 代码中提取数据。
     
  8. fyfei

    fyfei New Member

    Joined:
    Oct 7, 2005
    Messages:
    9,067
    Likes Received:
    46
    那就正则了,原理一样,就是要写那些元字符
     
  9. A君

    A君 Well-Known Member

    Joined:
    Aug 31, 2005
    Messages:
    19,987
    Likes Received:
    98
    好牛123
     
  10. tension

    tension New Member

    Joined:
    Jul 14, 2007
    Messages:
    1,314
    Likes Received:
    0
    想做小偷?
     
  11. DKEN

    DKEN Well-Known Member

    Joined:
    Aug 7, 2006
    Messages:
    3,358
    Likes Received:
    33
    问WC..............
     
  12. lane

    lane New Member

    Joined:
    Sep 5, 2005
    Messages:
    6,548
    Likes Received:
    29
    <table>
    </table>
    </tr>
    后面的换行留,剩下的换行也一起替换掉。
     
  13. 不学无术

    不学无术 Ulysses 的元神

    Joined:
    Aug 31, 2005
    Messages:
    16,714
    Likes Received:
    39
    明白人呀!

    我想学 PHP ,从百度音乐小偷开始入手。

    :)
     
  14. webren

    webren New Member

    Joined:
    Sep 6, 2008
    Messages:
    2,934
    Likes Received:
    0
    用dw,直接替换了.
     
  15. 不学无术

    不学无术 Ulysses 的元神

    Joined:
    Aug 31, 2005
    Messages:
    16,714
    Likes Received:
    39
    。。。。。。
     
  16. QinQi

    QinQi New Member

    Joined:
    Jun 21, 2007
    Messages:
    849
    Likes Received:
    0