2016-05-04 4 views
-1

ファイル管理システム用URLからPHPのパンくずリストを作成したいのですが、各ユーザーの ルートディレクトリはあるURLに次のようになります。ROOTDIRでアンカー形式のURLを使ってパンくずリストを作成するには

example.com/sfm?dir=uploads/sfm/root 

folder1 のfolder1をクリックすると、URLがあるという名前のフォルダがあります:folder1の中

example.com/sfm?dir=uploads/sfm/root/folder1 

は、

example.com/sfm?dir=uploads/sfm/root/folder1/folder2 
folder2 そのフォルダをクリックすると、URLになるという名前のフォルダがあります10

など... URLに基​​づいてフォルダへのアンカーを含むブレッドクラムを作成するにはどうすればよいですか?

答えて

1

あなたが正しく理解している場合は、$_GET['dir']という争いをして/で分割し、それぞれにリンクを張ってください。ここで

は、私はそれを行うだろうかです:

$crumbs=explode('/',$_GET['dir']); // this splits the sections of $_GET['dir'] separated by/into an array of values 
$url_pre=''; // we'll use this to keep track of the crumbs we've sifted through already 

// foreach cycles through each element in an array 
// $crumbs is the array, and $crumb is the current listing in the array we're looking at 
foreach($crumbs as $crumb){ 
    $url_pre.=.$crumb; 
    echo '<a href="?dir='.$url_pre.'">'.$crumb.'</a>'; 
    $url_pre.='/'; // add this after you echo the link, so that dir doesn't start with a/
} 
+0

はそれをテストし、それは素晴らしい作品!このソリューションをありがとう。 (小さな誤字: '$ url_pre。=。$ crumb;'は '$ url_pre。= $ crumb;'にする必要があります) –

関連する問題