Mega Code Archive

 
Categories / Php / File Directory
 

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>