I wrote a function that searches for a file within the include_path.
Here it is:

function ppcIncludize ($path) {

    // check for absolute path
    if ($path[0] == "/" || $path[1] == ":") {
        if (file_exists ($path)) {
            return $path;
        }

        return false;
    }

    $includePath = get_include_path();

    foreach (explode (PATH_SEPARATOR, $includePath) as $directory) {
        $tmpPath = "$directory/$path";

        if (file_exists ($tmpPath)) {
            return $tmpPath;
        }
    }

    return false;
}

This function only makes sense if the parameter given is a relative path to a file or folder and as this is not always the case I first check if it's an absolute path. So for unix systems it's quite easy, just need to check for / at the beginning, but on windows I am not sure as I don't use and have never developed under Windows. However as far as I know a absolute path starts with a drive letter e.g. C followed by a :. So I just check for the : . I am not a 100% sure if this works, so may anybody test it for me or at least tell me if I am write with my assumption about windows path names.

Thanks!

Jakob
--
Sun Certified Programmer for the Java 2 Platform, Standard Edition 5.0
_______________________________________________
New York PHP Community Talk Mailing List
http://lists.nyphp.org/mailman/listinfo/talk

NYPHPCon 2006 Presentations Online
http://www.nyphpcon.com

Show Your Participation in New York PHP
http://www.nyphp.org/show_participation.php

Reply via email to