本文整理汇总了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);
}
}