parse_urlのPHP Warning
ほ〜こういうのはエラーになるんだ
ちょっとおもしろいエラーがあったのでメモっておく
バグではなくPHP Warningね。
まずはコード
$hoge = parse_url("/xxx/xxx.php?url=http://hogehoge.jp/xxx.php?abc=sample01"); printf("%s\n",var_export($hoge, true));
結果のエラーがこれ
PHP Warning: parse_url(/xxx/test.php?url=http://hogehoge.jp/xxx.php?abc=sample01): Unable to parse URL in /home/xxx/test.php on line 2 PHP Stack trace: PHP 1. {main}() /home/xxx/test.php:0 PHP 2. parse_url() /home/xxx/test.php:2 Warning: parse_url(/xxx/test.php?url=http://hogehoge.jp/xxx.php?abc=sample01): Unable to parse URL in /home/xxx/test.php on line 2 Call Stack: 0.0004 44376 1. {main}() /home/xxx/test.php:0 0.0004 44492 2. parse_url() /home/xxx/test.php:2 false
プロトコル名とホスト名(http://hogehoge.jp/)を付けると問題なし
$hoge = parse_url("http://hogehoge.jp/xxx/xxx.php?url=http://hogehoge.jp/xxx.php?abc=sample01"); printf("%s\n",var_export($hoge, true));
結果はこんな感じ
array ( 'scheme' => 'http', 'host' => 'hogehoge.jp', 'path' => '/xxx/xxx.php', 'query' => 'url=http://hogehoge.jp/xxx.php?abc=sample01', )
GET引数のプロトコル名を除くと問題なし
$hoge = parse_url("/xxx/xxx.php?url=/hogehoge.jp/xxx.php?abc=sample01"); printf("%s\n",var_export($hoge, true));
結果はこんな感じ
array ( 'path' => '/xxx/xxx.php', 'query' => 'url=/hogehoge.jp/xxx.php?abc=sample01', )