當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。