php转义字符的应用,为转义字符需要转义为\。
<?php
//求b相对a的路径
$a="d:webfileab.php";
$b="d:webfiledehello.php";
$len=strlen($a);
$relatePath='';
$count=0;
$slash=0;
for($i=0;$i<$len;$i++)
{
$c1=substr($a,$i,1);
$c2=substr($b,$i,1);
if($c1==$c2)
{
$count++;
if($c1=="\")
$slash++;
continue;
}
else
{
break;
}
}
for($j=0;$j<$slash;$j++)
{
$relatePath.="..\";
}
$relatePath.=substr($b,$count);
echo $relatePath;
?>
