<?php
$DEBUG=false;
$VERBOSE=false;
// remove leaving slahs or backslash
function noSlash($pth)
{
$c=substr($pth,-1);
if(($c==="/")||($c==="\\"))
{
return substr($pth,0,-1);
}
return $pth;
}
function setWindows($name)
{
for($i=0;$i<strlen($name);$i++)
{
if($name{$i}==="/")
{
$name{$i}="\\";
}
}
return $name;
}
// convert local to URL and to unix
function setURL($name)
{
for($i=0;$i<strlen($name);$i++)
{
if($name{$i}==="\\")
{
$name{$i}="/";
}
}
return $name;
}
function textToUTF8($content)
{
$content=str_replace("&","&",$content);
$content=str_replace("<","<",$content);
$content=str_replace(">",">",$content);
return $content;
}
// if drive letter in path, change drive
function changeDir($pth)
{
chdir($pth);
global $DEBUG;
global $VERBOSE;
if($DEBUG&&$VERBOSE)
{
echo "Now path is", " ", getcwd(), "\n";
}
return;
}
// Check if the source ends with the string search
function endWith($source,$search)
{
$last=substr($search,-1);
if(($last==="/")||($last==="\\"))
{
$search=substr($search,0,-1);
}
$lsea=strlen($search);
$lsrc=strlen($source);
if($lsrc<$lsea)
{
return false;
}
if(substr($source,-$lsea)===$search)
{
return true;
}
return false;
}
// test if this is a remote address (host included in the string)
function hasProtocol($theurl)
{
$lowname=strtolower(ltrim($theurl));
if(substr($lowname,0,7)==="http://")
{
return true;
}
if(substr($lowname,0,6)==="ftp://")
{
return true;
}
if(substr($lowname,0,8)==="https://")
{
return true;
}
return false;
}
function siteOffset($theurl)
{
$offset=0;
$offset=strpos($theurl,"http://");
if($offset===false)
{
$offset=strpos($theurl,"ftp://");
if($offset===false)
{
$offset=strpos($theurl,"https://");
if($offset!=false)
{
$offset+=8;
}
}
else
{
$offset+=6;
}
}
else
{
$offset+=7;
}
return $offset;
}
// return remote part and local part
function splitURL($theurl)
{
$offset=siteOffset($theurl);
if($offset===false)
{
return array("",$theurl);
}
$offset=strpos($theurl,"/",$offset);
if($offset===false)
{
return array($theurl,"");
}
return array(substr($theurl,0,$offset),substr($theurl,$offset+1));
}
// get the remote part of URL
function getURL($theurl)
{
$offset=siteOffset($theurl);
$offset=strpos($theurl,"/",$offset);
if($offset===false)
{
return $theurl;
}
return substr($theurl,0,$offset);
}
?>