当前位置: 首页>>代码示例>>PHP>>正文


PHP Url::getFragment方法代码示例

本文整理汇总了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();
 }
开发者ID:cienciastar,项目名称:Embed,代码行数:14,代码来源:UrlRedirect.php

示例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');
 }
开发者ID:inad9300,项目名称:bed.php,代码行数:18,代码来源:UrlTest.php

示例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();
 }
开发者ID:vakata,项目名称:http,代码行数:48,代码来源:Url.php

示例4: testGetFragment

 /**
  * @param $url
  * @param $expectedFragment
  *
  * @dataProvider dataProviderForTestGetFragment
  */
 public function testGetFragment($url, $expectedFragment)
 {
     $url = new Url($url);
     $this->assertEquals($expectedFragment, $url->getFragment());
 }
开发者ID:fastfeed,项目名称:url,代码行数:11,代码来源:UrlTest.php

示例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());
 }
开发者ID:seytar,项目名称:psx,代码行数:11,代码来源:UrlTest.php

示例6: testGetFragment

 public function testGetFragment()
 {
     $this->assertEquals('bottom', $this->absoluteUrl->getFragment());
 }
开发者ID:starweb,项目名称:starlit-utils,代码行数:4,代码来源:UrlTest.php

示例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);
     }
 }
开发者ID:heatery,项目名称:Embed,代码行数:11,代码来源:UrlRedirect.php


注:本文中的Url::getFragment方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。