PHP Classes

File: examples/demo_05.php

Recommend this page to a friend!
  Packages of J.   HTML SQL   examples/demo_05.php   Download  
File: examples/demo_05.php
Role: Example script
Content type: text/plain
Description: Example 5 - Shows a advanced query (with substr)
Class: HTML SQL
Parse and extract information from HTML using SQL
Author: By
Last change:
Date: 20 years ago
Size: 937 bytes
 

 

Contents

Class file image Download
<?php

    /*
    ** htmlSQL - Example 5
    **
    ** Shows a advanced query (with substr)
    */

    include_once("../snoopy.class.php");
    include_once("../htmlsql.class.php");
    
    $wsql = new htmlsql();
    
    // connect to a URL
    if (!$wsql->connect('url', 'http://codedump.jonasjohn.de/links.htm')){
        print 'Error while connecting: ' . $wsql->error;
        exit;
    }
    
    /* execute a query:
       
       This query returns all links of an document that not start with / 
       ( / = internal links)
    */
    if (!$wsql->query('SELECT * FROM a WHERE substr($href,0,1) != "/"')){
        print "Query error: " . $wsql->error; 
        exit;
    }

    // fetch results as object and format as HTML links:
    foreach($wsql->fetch_objects() as $obj){
    
        print '<a href="'.$obj->href.'">'.$obj->text.'</a><br/>';
        print "\n";
        
    }
    
?>