本文整理匯總了PHP中Grav\Common\Utils::substrToString方法的典型用法代碼示例。如果您正苦於以下問題:PHP Utils::substrToString方法的具體用法?PHP Utils::substrToString怎麽用?PHP Utils::substrToString使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類Grav\Common\Utils
的用法示例。
在下文中一共展示了Utils::substrToString方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: buildHostname
/**
* Return the hostname from $_SERVER, validated and without port
*
* @return string
*/
private function buildHostname()
{
$hostname = isset($_SERVER['HTTP_HOST']) ? $_SERVER['HTTP_HOST'] : (isset($_SERVER['SERVER_NAME']) ? $_SERVER['SERVER_NAME'] : 'localhost');
// Remove port from HTTP_HOST generated $hostname
$hostname = Utils::substrToString($hostname, ':');
// Validate the hostname
$hostname = $this->validateHostname($hostname) ? $hostname : 'unknown';
return $hostname;
}
示例2: __construct
/**
* Constructor.
*/
public function __construct()
{
$name = isset($_SERVER['HTTP_HOST']) ? $_SERVER['HTTP_HOST'] : (isset($_SERVER['SERVER_NAME']) ? $_SERVER['SERVER_NAME'] : 'localhost');
// Remove port from HTTP_HOST generated $name
$name = Utils::substrToString($name, ':');
// Validate the hostname
$name = preg_match(Uri::HOSTNAME_REGEX, $name) ? $name : 'unknown';
$port = isset($_SERVER['SERVER_PORT']) ? $_SERVER['SERVER_PORT'] : 80;
$uri = isset($_SERVER['REQUEST_URI']) ? $_SERVER['REQUEST_URI'] : '';
$root_path = str_replace(' ', '%20', rtrim(substr($_SERVER['PHP_SELF'], 0, strpos($_SERVER['PHP_SELF'], 'index.php')), '/'));
// set the base
if (isset($_SERVER['HTTPS'])) {
$base = strtolower(@$_SERVER['HTTPS']) == 'on' ? 'https://' : 'http://';
} else {
$base = 'http://';
}
// add the sever name
$base .= $name;
// add the port of needed
if ($port != '80' && $port != '443') {
$base .= ":" . $port;
}
// check if userdir in the path and workaround PHP bug with PHP_SELF
if (strpos($uri, '/~') !== false && strpos($_SERVER['PHP_SELF'], '/~') === false) {
$root_path = substr($uri, 0, strpos($uri, '/', 1)) . $root_path;
}
// set hostname
$address = isset($_SERVER['REMOTE_ADDR']) ? $_SERVER['REMOTE_ADDR'] : '::1';
// check for localhost variations
if ($name == 'localhost' || $address == '::1' || $address == '127.0.0.1') {
$this->host = 'localhost';
} else {
$this->host = $name;
}
$this->base = $base;
$this->root = $base . $root_path;
$this->url = $base . $uri;
}
示例3: testSubstrToString
public function testSubstrToString()
{
$this->assertEquals('en', Utils::substrToString('english', 'glish'));
$this->assertEquals('english', Utils::substrToString('english', 'test'));
$this->assertNotEquals('en', Utils::substrToString('english', 'lish'));
}