//add the tail slash if not exist
//eg: from files/doc/docbook to files/doc/docbook/
function addTailSlash($str)
{
if(substr($str, -1) != "/")
{
$str = $str."/";
}
return $str;
}
例 2.1. addTailSlash使用范例
//add tail slash
$homePath = $this->addTailSlash($homePath);
//echo "homePath=".$homePath."<br />";
//remove the first slash if exist
//eg: from /files/doc/docbook to files/doc/docbook
function removeFirstSlash($str)
{
if(substr($str, 0, 1) == "/")
{
$str = substr($str, 1);
}
return $str;
}
//eg: check txt is in array("txt", "html", "pdf")
function strExistInArr($str, $arr)
{
if($arr[0] == "*")
{
$found = True;
}
else
{
$found = False;
$arrLen = count($arr);
for($i=0; $i<$arrLen; $i++)
{
//if(0 == strcmp($str, $arr[$i]))
if($str == $arr[$i])
{
$found = True;
break;
}
}
}
return $found;
}
//eg: from "*.html;*.txt;" to array("html", "txt")
function genValidSuffix($fileType)
{
$validSuf = array();
$splitedArr = explode(";", $fileType);
$arrSize = count($splitedArr);
//echo "splited arrary size=".$arrSize."<br />";
for($i=0; $i<$arrSize; $i++)
{
$singleSufDef = $splitedArr[$i];
//echo "singleSufDef=".$singleSufDef."<br />";
if($singleSufDef && ($singleSufDef != ""))
{
//echo "singleSufDef not null <br />";
$suffix = str_replace("*.", "", $singleSufDef);
//echo "suffix=".$suffix."<br />";
if($suffix == "*")
{
//echo "found & suffix <br />";
$validSuf = array("*");
break;
}
else
{
//echo "add $suffix into array <br />";
array_push($validSuf, $suffix);
}
}
}
return $validSuf;
}
例 2.3. genValidSuffix使用范例
//$validSuf = array("html", "htm", "txt", "pdf");
$validSuf = $this->genValidSuffix($fileType);





