Clean Path by Regular Expressions : Directory « File Directory « PHP






Clean Path by Regular Expressions

<html>
<body>
<?php
if (isset($_POST['posted'])) {
   $path = $_POST['path'];
   $outpath = ereg_replace("\.[\.]+", "", $path);
   $outpath = ereg_replace("^[\/]+", "", $outpath);
   $outpath = ereg_replace("^[A-Za-z][:\|][\/]?", "", $outpath);
   echo "The old path is " . $path . " and the new path is " . $outpath;
}
?>
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="POST">
<input type="hidden" name="posted" value="true">
Enter your file path for cleaning:
<input type="text" name="path" size="30">
<input type="submit" value="Clean">
</form>
</body>
</html>


           
       








Related examples in the same category

1.Listing the Contents of a Directory with readdir()
2.Calculate the size for a directory
3.readdir: Read entry from directory handle
4.scandir: List files and directories inside the specified path
5.The current working directory
6.Print all files under a directory
7.Read the content from a directory
8.Reading Contents from a Directory