首页 > 开发 > PHP > 正文

用SQL语句读取XML和HTML文档

2024-05-04 22:59:48
字体:
来源:转载
供稿:网友
  • 本文来源于网页设计爱好者web开发社区http://www.html.org.cn收集整理,欢迎访问。
  • 今天从phpclasses.org上发现的一个超牛的php类,这个类最特别的是可以用select语句来从xml和html文档中读取特定的数据。例如下面是一个例子:

    <?php

        /*
        ** htmlsql - example 1
        **
        ** 一个查询的简单例子  
     */
        //包含类文件
        include_once("../snoopy.class.php");
        include_once("../htmlsql.class.php");
        //创建对象
        $wsql = new htmlsql();
       
        // 连接上url
        if (!$wsql->connect('url', '/')){
            print 'error while connecting: ' . $wsql->error;
            exit;
        }
       
        /* 执行查询
            select * from a 读取phpchina.cn首页的html中的所有的<a>标记
        */
        if (!$wsql->query('select * from a ')){
            print "query error: " . $wsql->error;
            exit;
        }

        // 输出结果:
        foreach($wsql->fetch_array() as $row){
            print_r($row);
            /*
            $row 是像下面的一个数组:
            array (
                [href] => /index.html
                [tagname] => a
                [text] => 首页
            )
            */ 
        }
    ?>

    这个类的作者:jonas john
    个人主页:http://www.jonasjohn.de/
    年龄:20

    发表评论 共有条评论
    用户名: 密码:
    验证码: 匿名发表