使用_-_--或_-_-_进行url斜线和空格替换

时间:2015-09-22 08:45:15

标签: php url str-replace

我有来自给定路径的代码,使得像痕迹导航一样。我没有写过那段代码,但我认为除了url替换中的两件事情我理解它。

代码是这样的,我无法弄清楚,为什么用_-_--替换空格并用_-_-_斜杠。这有什么共同点吗?

function listLinksRecursive($path){

echo "<br>recursive : " . $path;
$path = str_replace("X:/","",$path);
$path = str_replace("X:","",$path);
$header = str_replace("_"," ", $path);
echo "<br>first header ". $header;
$header = str_replace("-"," ", $header);
echo "<br>second header ". $header;
echo "<br>";
$linksarray = explode ("/",$header);
$linksarrayreal = explode("/",str_replace(" ","_-_--",$path));
var_dump($linksarray);
echo "<br>";
var_dump($linksarrayreal);

echo "FOLDER: ";
echo ("<a href='http://sjabcz-vyv-bck/cae/index.php?lvl=0&idpath=' rel='nofollow'>04_Knowledge-base</a> / ");

for ($i=0; $i < count($linksarray); $i++){
    $linkpath = "";
    for ($j = 0; $j <=$i; $j++){

        $linkpath = $linkpath . $linksarrayreal[$j];
        if ($j < $i){
            $linkpath = $linkpath . "_-_-_";
        }
    }

    if ($i < count($linksarray)-1){
        echo ("<a href = 'http://sjabcz-vyv-bck/cae/index.php?lvl=0&idpath=$linkpath' rel='nofollow'>$linksarray[$i]</a> / ");
    }

    if ($i == count($linksarray)-1){
        echo ("<b>$linksarray[$i]</b>");
    }
}

echo "<p>";

}

0 个答案:

没有答案