- preg_match: documentation ( source)
- preg_replace: documentation ( source)
<?php
$scandir = "home:///Pierpaolo/file.txt";
$scandir = preg_replace("/\/$/", "", $scandir);
$scandir = preg_replace("/\/\.\.\/?/", "/", $scandir);
$scandir = preg_replace("/\/$/", "", $scandir);
echo $scandir;
if ( (preg_match("/^([A-z0-9\-_]+)?\:\/\/?(.*)/", $scandir, $matches)) !== false ) {
if ( sizeof($matches) === 3 ) {
$protocol = "{$matches[1]}://";
$dirname = $matches[2];
}
}
echo $protocol." - ".$dirname ;