php使用正则表达式处理路径

标签: php正则表达式路径   时间:2016-08-07
本文章向大家介绍php如何使用正则表达式处理路径,主要使用到php的ereg_replace函数,需要的朋友可以参考一下本文章。

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>

原文地址:http://www.manongjc.com/article/1319.html

分享到