0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

PHP URL分ける GETパラメーター

Posted at

PHP URL分離

クエリ以前(?以前)のURLが欲しかったのでメモします。

url.php
$url = 'http://www.example.com/hoge.html?param1=foo&param2=bar';
$sample_url = parse_url($url);
var_dump($sample_url);

結果

array(4) {
  ["scheme"]=>
  string(4) "http"
  ["host"]=>
  string(15) "www.example.com"
  ["path"]=>
  string(10) "/hoge.html"
  ["query"]=>
  string(21) "param1=foo&param2=bar"
}

今のページのURL分離したかったので

parse_url($_SERVER['REQUEST_URI']);

↑を使った。

他にも便利に分けられる。
詳しくはphpヘルプ

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?