- <html>
- <head>
- <title>Entre deux pages.</title>
- </head>
- <body>
- <?php
- function urlplus($chemin, $chemin_relatif){
- $chemin=$chemin.'/'.$chemin_relatif;
- $chemin=preg_replace('/(\/[^\/]*\.\.\/)|(\/\/)/','/',$chemin);
- return $chemin;
- }
- function list_liens($a, $url){
- preg_match_all('/href="(\S+)"/i', $a, $tab);
- $tab=$tab[1];
- foreach ($tab as $a=>$b)
- if (substr($b, 0, 7)!=='http://')
- $tab[$a]=urlplus($url,$b);
- return $tab;
- }
- function search_page($tour, $_POST, $URL, $allready){
- while (true)
- foreach ($URL[$tour] as $b)
- foreach ($b as $c)
- if (!in_array($c, $allready)){
- $allready[]=$c;
- $a=@file_get_contents($c) or $a=false;
- if ($a!==false){
- $URL[$tour+1][$c]=list_liens($a, $c);
- if (in_array($_POST['URL2'],$URL[$tour+1][$c]))
- return array($tour+1, $URL, $allready);
- }
- }
- }
- if (isset($_POST['URL1'])){
- echo 'De '.$_POST['URL1'],' à ', $_POST['URL2'],'<br />';
- $URL=array();
- $tour=0;
- $a=file_get_contents($_POST['URL1']);
- $URL[0][$_POST['URL1']]=list_liens($a, $_POST['URL1']);
- $allready=array($_POST['URL1']);
- list($tour, $URL, $allready)=search_page(&$tour, $_POST, &$URL, &$allready);
- echo ($tour+1),'liens<br />';
- $url_search=$_POST['URL2'];
- for (;$tour>0;$tour--)
- foreach ($URL[$tour] as $c=>$d)
- if (in_array($url_search, $d)){
- echo $c.'<br />';
- $url_search=$c;
- }
- echo $_POST['URL2'];
- }else{
- echo '<p>Entrez deux URLS, nous vous donnerons le "chemin" le plus court pour aller de l\'une à l\'autre... Le nombre de liens et l\'URL de ces liens.</p>';
- }
- ?>
- <hr />
- <form action="?" method="post">
- <p>de : <input type="text" name="URL1" /></p>
- <p>à : <input type="text" name="URL2" /></p>
- <input type="submit" />
- </form>
- </body>
- </html>
<html>
<head>
<title>Entre deux pages.</title>
</head>
<body>
<?php
function urlplus($chemin, $chemin_relatif){
$chemin=$chemin.'/'.$chemin_relatif;
$chemin=preg_replace('/(\/[^\/]*\.\.\/)|(\/\/)/','/',$chemin);
return $chemin;
}
function list_liens($a, $url){
preg_match_all('/href="(\S+)"/i', $a, $tab);
$tab=$tab[1];
foreach ($tab as $a=>$b)
if (substr($b, 0, 7)!=='http://')
$tab[$a]=urlplus($url,$b);
return $tab;
}
function search_page($tour, $_POST, $URL, $allready){
while (true)
foreach ($URL[$tour] as $b)
foreach ($b as $c)
if (!in_array($c, $allready)){
$allready[]=$c;
$a=@file_get_contents($c) or $a=false;
if ($a!==false){
$URL[$tour+1][$c]=list_liens($a, $c);
if (in_array($_POST['URL2'],$URL[$tour+1][$c]))
return array($tour+1, $URL, $allready);
}
}
}
if (isset($_POST['URL1'])){
echo 'De '.$_POST['URL1'],' à ', $_POST['URL2'],'<br />';
$URL=array();
$tour=0;
$a=file_get_contents($_POST['URL1']);
$URL[0][$_POST['URL1']]=list_liens($a, $_POST['URL1']);
$allready=array($_POST['URL1']);
list($tour, $URL, $allready)=search_page(&$tour, $_POST, &$URL, &$allready);
echo ($tour+1),'liens<br />';
$url_search=$_POST['URL2'];
for (;$tour>0;$tour--)
foreach ($URL[$tour] as $c=>$d)
if (in_array($url_search, $d)){
echo $c.'<br />';
$url_search=$c;
}
echo $_POST['URL2'];
}else{
echo '<p>Entrez deux URLS, nous vous donnerons le "chemin" le plus court pour aller de l\'une à l\'autre... Le nombre de liens et l\'URL de ces liens.</p>';
}
?>
<hr />
<form action="?" method="post">
<p>de : <input type="text" name="URL1" /></p>
<p>à : <input type="text" name="URL2" /></p>
<input type="submit" />
</form>
</body>
</html>