php使用正则表达式处理路径,源代码如下:

<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);
   /* http://www.manongjc.com/article/1319.html */
   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>
收藏 打印