本文整理汇总了PHP中CString::stripStart方法的典型用法代码示例。如果您正苦于以下问题:PHP CString::stripStart方法的具体用法?PHP CString::stripStart怎么用?PHP CString::stripStart使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CString
的用法示例。
在下文中一共展示了CString::stripStart方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: __construct
/**
* Creates a URL path from a path string or as empty.
*
* If a source path string is provided, it should start with "/". Just like in any valid URL, the path string is
* not expected to contain characters that cannot be represented literally and percent-encoding is expected to be
* used for any such characters. No trailing "/" are stripped off the path string, so if the path is e.g.
* "/comp0/comp1/", it produces an empty string as the last component.
*
* @param string $path **OPTIONAL. Default is** *create an empty URL path*. A string with the source path.
*/
public function __construct($path = null)
{
assert('!isset($path) || is_cstring($path)', vs(isset($this), get_defined_vars()));
assert('!isset($path) || CString::startsWith($path, "/")', vs(isset($this), get_defined_vars()));
if (isset($path)) {
$path = CString::stripStart($path, "/");
$this->m_components = CString::split($path, "/");
$len = CArray::length($this->m_components);
for ($i = 0; $i < $len; $i++) {
$this->m_components[$i] = CUrl::leaveTdNew($this->m_components[$i]);
}
} else {
$this->m_components = CArray::make();
}
}
示例2: normalize
/**
* Normalizes a path by removing any trailing slashes, any redundant slashes, any references to the current
* directory, and any references to the parent directory where possible, and returns the new path.
*
* For example, "/path//./dir-a/.././to//../dir-b/" is normalized to "/path/dir-b".
*
* @param string $path The path to be normalized (can be absolute or relative).
* @param bool $targetIsExecutable **OPTIONAL. Default is** `false`. Tells whether the path's target should be
* treated as an executable so that, if the path starts with ".", the resulting path will start with "." too and
* the "." will not be removed as a reference to the current directory.
*
* @return CUStringObject The normalized path.
*/
public static function normalize($path, $targetIsExecutable = false)
{
assert('is_cstring($path) && is_bool($targetIsExecutable)', vs(isset($this), get_defined_vars()));
assert('!CString::isEmpty($path)', vs(isset($this), get_defined_vars()));
$path = CRegex::replace($path, "/\\/{2,}/", "/");
// normalize consecutive slashes
$path = CString::stripEnd($path, "/");
// remove the trailing slash, if any
if (CString::isEmpty($path)) {
return "/";
}
$path = CRegex::remove($path, "/\\/\\.(?=\\/|\\z)/");
// remove any "/." followed by a slash or at the end
if (CString::isEmpty($path)) {
return "/";
}
if (!$targetIsExecutable) {
$path = CString::stripStart($path, "./");
}
$pathIsAbsolute;
if (!CString::startsWith($path, "/")) {
$pathIsAbsolute = false;
} else {
$pathIsAbsolute = true;
$path = CString::substr($path, 1);
}
if (!CString::find($path, "/")) {
if ($pathIsAbsolute) {
if (!CString::equals($path, "..")) {
$path = "/{$path}";
} else {
$path = "/";
}
}
return $path;
}
// Recompose the path.
$components = CString::split($path, "/");
$newComponents = CArray::make();
$len = CArray::length($components);
for ($i = 0; $i < $len; $i++) {
$comp = $components[$i];
$lastAddedComp = "";
$noCompsAddedYet = CArray::isEmpty($newComponents);
if (!$noCompsAddedYet) {
$lastAddedComp = CArray::last($newComponents);
}
if (CString::equals($comp, "..")) {
if ($noCompsAddedYet || CString::equals($lastAddedComp, "..") || CString::equals($lastAddedComp, ".")) {
if (!($noCompsAddedYet && $pathIsAbsolute)) {
CArray::push($newComponents, $comp);
}
} else {
CArray::pop($newComponents);
}
} else {
CArray::push($newComponents, $comp);
}
}
$path = CArray::join($newComponents, "/");
if ($pathIsAbsolute) {
$path = "/{$path}";
} else {
if (CString::isEmpty($path)) {
$path = ".";
}
}
return $path;
}
示例3: initScriptRelFp
/**
* Returns the path to the file of the initially run script, relative to the Document Root directory.
*
* @return CUStringObject The path to the file of the initially run script, relative to the Document Root
* directory.
*/
public static function initScriptRelFp()
{
return CString::stripStart($_SERVER["SCRIPT_NAME"], "/");
}