Login   Register  
PHP Classes
elePHPant
Icontem

File: example.php

Recommend this page to a friend!
Stumble It! Stumble It! Bookmark in del.icio.us Bookmark in del.icio.us
  Classes of Carlos Reche  >  PathParser  >  example.php  >  Download  
File: example.php
Role: Example script
Content type: text/plain
Description: File with examples of how to use PathParser class.
Class: PathParser
Parse URL or file paths and compute relative paths
Author: By
Last change:
Date: 9 years ago
Size: 1,813 bytes
 

Contents

Class file image Download
<?php

echo '<pre style="line-height: 25px;">';


// Loads PathManager class
require_once "class.pathparser.php";


$path 'http://www.php.net:80/./donwloads/../faq/.././manual/en/install.php?version=502#top';

$Path = new PathParser($path);

echo 
"\nOriginal path: " $path;
echo 
"\nResolved path: " $Path->path;
echo 
"\n\nPath parts: \n";
print_r($Path->parse());



echo 
"\n\n\n    Dirty paths:\n";

$paths[] = 'C://////////Windows//////System';               //  C:/Windows/System/
$paths[] = 'C:\HTML\javascript\..\examples\colors.html';    //  C:/HTML/examples/colors.html
$paths[] = '/root/./wwwroot/scripts/../././webpage';        //  /root/wwwroot/webpage/
$paths[] = 'wwwroot/webpage/../index.php?querystring';      //  wwwroot/index.php?querystring
$paths[] = 'http://www.php.net/manual/en/../../downloads';  //  http://www.php.net/downloads/
$paths[] = 'http://www.php.net/downloads/.././docs.php';    //  http://www.php.net/docs.php
$paths[] = '../downloads/../docs.php';                      //  ../docs.php
$paths[] = 'localhost//projetos/../_arquivos/../';          //  localhost/
$paths[] = 'C:/downloads/../../../';                        //  C:/
$paths[] = 'downloads/../../../';                           //  ../../

foreach ($paths as $path)
{
    echo 
"\n&quot;" $path "&quot;  =  &quot;" $Path->fix($path) . "&quot;";
}



echo 
"\n\n\n    Finding relative paths:\n";


$path_a 'http://www.php.net/manual/en/install.php';
$path_b 'http://www.php.net/downloads';

echo 
"\nPath A:  " $path_a;
echo 
"\nPath B:  " $path_b;
echo 
"\nA to B:  " $Path->findRelativePath($path_a$path_b); //  ../../downloads/
echo "\nB to A:  " $Path->findRelativePath($path_b$path_a); //  ../manual/en/install.php



echo '</pre>';

?>