PHP Classes

File: linkExtractor.function.php

Recommend this page to a friend!
  Classes of Andrea Giammarchi   Link Extractor   linkExtractor.function.php   Download  
File: linkExtractor.function.php
Role: Example script
Content type: text/plain
Description: With this function is more simple use LinkExtractor class ( maybe for newbyes in oop )
Class: Link Extractor
Extract links from a string, file or an HTML page
Author: By
Last change:
Date: 19 years ago
Size: 841 bytes
 

Contents

Class file image Download
<?php
// USE THIS FUNCTION TO USE AUTOMATICALLY LinkExtractor CLASS
require( "LinkExtractor.class.php" );

function
linkExtractor( $what, $url = false ) {
   
// andr3a 18/06/2004 [ www.3site.it ]

    // linkExtractor( $string_url_or_file [, true/false ] )
    // true if $string_or_url is an url or a file
    // false or anything if is a string
   
   
$myLinks = &new LinkExtractor();
    if(
$url == false ) {
       
$myLinks->parseString( $what );
    }
    elseif(
$url == true ) {
            if(
$myLinks->parseUrl( $what ) == false ) {
                return
false;
        }
    }
    return
$myLinks->getLinks();
}

// EXAMPLE
$url = "http://www.php.net/"; // site to parse

$arrayLinks = &linkExtractor( $url, true );

if(
$arrayLinks != false ) {
    for(
$a = 0, $b = count( $arrayLinks ); $a < $b; $a++ ) {
        echo
$arrayLinks[$a]."<br />";
    }
}
?>