本文整理匯總了PHP中Url::getFragment方法的典型用法代碼示例。如果您正苦於以下問題:PHP Url::getFragment方法的具體用法?PHP Url::getFragment怎麽用?PHP Url::getFragment使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類Url
的用法示例。
在下文中一共展示了Url::getFragment方法的7個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: hashBang
/**
* Resolve an url with hashbang.
*
* @param Url $url
*
* @return string
*/
protected static function hashBang(Url $url)
{
if ($path = preg_replace('|^(/?!)|', '', $url->getFragment())) {
return $url->withPath($url->getPath() . $path)->getUrl();
}
return $url->getUrl();
}
示例2: testUrl
function testUrl()
{
$url = new Url(self::TEST_URL);
$this->assertEquals($url->getFull(), self::TEST_URL);
$this->assertEquals($url->getScheme(), 'https');
$this->assertEquals($url->getHost(), 'www.google.com');
$this->assertEquals($url->getPort(), '80');
$this->assertEquals($url->getPath(), '/some_path');
// The HTML entities remain intact
$this->assertEquals($url->getQuery(), 'some=query&something=%20weird');
// The HTML entities are resolved
$this->assertEquals($url->getParam('some'), 'query');
$this->assertEquals($url->getParam('something'), ' weird');
$this->assertEquals($url->getParams(), ['some' => 'query', 'something' => ' weird']);
$this->assertEquals($url->getFragment(), 'some_fragment');
$this->assertEquals($url->getUser(), 'user');
$this->assertEquals($url->getPass(), 'pass');
}
示例3: linkTo
/**
* get a link from the current URL to another one
* @param UrlInterface|string $url the URL to link to
* @param boolean $forceAbsolute should an absolute path be used, defaults to `true`)
* @return string the link
*/
public function linkTo($url, $forceAbsolute = true)
{
if (is_string($url)) {
$url = new Url($url);
}
$str = (string) $url;
if ($this->getScheme() !== $url->getScheme()) {
return $str;
}
$str = preg_replace('(^[^/]+//)', '', $str);
if ($this->getHost() !== $url->getHost() || $this->getPort() !== $url->getPort()) {
return '//' . $str;
}
$str = preg_replace('(^[^/]+)', '', $str);
if ($this->getPath() !== $url->getPath()) {
if ($forceAbsolute) {
return $str;
}
$cnt = 0;
$tseg = $this->getSegments();
$useg = $url->getSegments();
foreach ($tseg as $k => $v) {
if (!isset($useg[$k]) || $useg[$k] !== $v) {
break;
}
$cnt++;
}
$str = './' . str_repeat('../', count($useg) - $cnt) . implode('/', array_slice($useg, $cnt));
if ($url->getQuery()) {
$str .= '?' . $url->getQuery();
}
if ($url->getFragment()) {
$str .= '#' . $url->getFragment();
}
return $str;
}
$str = preg_replace('(^[^?]+)', '', $str);
if ($this->getQuery() !== $url->getQuery() || $url->getFragment() === null) {
return $str;
}
return '#' . $url->getFragment();
}
示例4: testGetFragment
/**
* @param $url
* @param $expectedFragment
*
* @dataProvider dataProviderForTestGetFragment
*/
public function testGetFragment($url, $expectedFragment)
{
$url = new Url($url);
$this->assertEquals($expectedFragment, $url->getFragment());
}
示例5: testUrlFragmentEncoding
public function testUrlFragmentEncoding()
{
$url = new Url('http://127.0.0.1/foobar?bar=foo#!"#$%&\'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~');
$this->assertEquals('http', $url->getScheme());
$this->assertEquals(null, $url->getUserInfo());
$this->assertEquals('127.0.0.1', $url->getHost());
$this->assertEquals(null, $url->getPort());
$this->assertEquals('/foobar', $url->getPath());
$this->assertEquals(array('bar' => 'foo'), $url->getParameters());
$this->assertEquals('!"#$%&\'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~', $url->getFragment());
}
示例6: testGetFragment
public function testGetFragment()
{
$this->assertEquals('bottom', $this->absoluteUrl->getFragment());
}
示例7: hashBang
/**
* Resolve an url with hashbang
*
* @param Url $url
*/
protected static function hashBang(Url $url)
{
if ($path = preg_replace('|^(/?!)|', '', $url->getFragment())) {
$url->setPath($url->getPath() . $path);
}
}