本文整理汇总了PHP中WebUtils::getBaseURL方法的典型用法代码示例。如果您正苦于以下问题:PHP WebUtils::getBaseURL方法的具体用法?PHP WebUtils::getBaseURL怎么用?PHP WebUtils::getBaseURL使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类WebUtils
的用法示例。
在下文中一共展示了WebUtils::getBaseURL方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: setURL
/** ************************************************
* Trims whitespace off the url, then removes the /
* off the right side of the url if it exists.
* Gets the base url and the url with just it's path
* @param:
* @return: null
* @throws:
** ***********************************************/
public function setURL($url)
{
if (is_string($url) && WebUtils::isValidURL($url)) {
$url = rtrim(trim($url), '/');
$this->sURL = $url;
$base = WebUtils::getBaseURL($url);
if ($base == '') {
$base = $url;
}
$this->sBaseURL = $base;
$path = WebUtils::getCurrentPathURL($url);
if ($path == '') {
$path = $url;
}
$this->sCurrentPathURL = $path;
} else {
throw new Exception('AnchorParser.setURL accepts valid URLs only.');
}
}
示例2: traversRelPath
/** ************************************************
* This function tries to travers the given url's path
* but will not work if the realtive path is not traversable
* with the given url.
* @param: $url string; a url
* @param: $relPath string; a relative path
* @return: string; the url after it was traversed by
* relPath. Or false if there was some error/problem
* TODO: Do a better job of adding / in the return string
***************************************************/
public static function traversRelPath($sUrl, $relPath)
{
if (!WebUtils::isValidURL($sUrl)) {
return false;
}
$baseP = WebUtils::getCurrentPathURL($sUrl);
$baseU = WebUtils::getBaseURL($sUrl);
$path = WebUtils::getPathOnly($sUrl);
$path = explode('/', $path);
$relPath = explode('/', $relPath);
//echo '<pre>Path '. var_export($path, true) . '</pre><br/>';
//echo '<pre>rel '. var_export($relPath, true) . '</pre><br/>';
foreach ($relPath as $r) {
if ($r != '.' && $r != '..') {
array_push($path, array_shift($relPath));
continue;
} else {
if ($r == '.') {
array_shift($relPath);
continue;
} else {
if ($r == '..') {
array_shift($relPath);
if (array_pop($path) == null) {
return false;
}
}
}
}
}
return rtrim($baseU . implode('/', $path) . implode('/', $relPath), '/');
}