PHP Classes

File: example.class.path.php

Recommend this page to a friend!
  Classes of Rémy Sanchez   Path   example.class.path.php   Download  
File: example.class.path.php
Role: Example script
Content type: text/plain
Description: An example script
Class: Path
Manipulate file and directory path strings
Author: By
Last change:
Date: 15 years ago
Size: 1,225 bytes


Class file image Download
// First of all, we need to include the class
require_once "class.path.php";

// Then we'll create a new path, with all options
// In order, the options are : the path string, is the path pointing a
// directory, is there some string to put before the path, and what is the
// separator ?
$path = new Path("/some/path/to/test/", true, "http://", "/");

// Obviously, I want to output an URL, just look
echo "It's looking like an URL: $path\n";

// Now I create a new path with a completely different delimiter
$path2 = new Path("\a\file.php", false, null, "\\");

// And I can just append it to the previous one
// We could have done $path->b($path2), but it would have returned a new object
// with $path2 appened instead of changing $path

// And turn this into a SMB share
"Now it's a SMB share: $path\n";

// You can also use new basename() and dirname()
// Note that dirname() returns a Path and not a string
echo "The parent directory is: " . $path->dirname() . "\n";
"The pointed file is: " . $path->basename() . "\n";
"But without its extension it would be: " . $path->basename(".php") . "\n";