LoginSignup
0
0

More than 5 years have passed since last update.

PHPで正規表現を使わずHTTPステータスコードを取得する

Last updated at Posted at 2017-07-11

PHPでHTTPステータスコードを取得しようとググったところ、
正規表現で抜き出しているのが多くて、他にやり方がないか調べたところ以下のやり方で取得できた。

$url = 'http://example.co.jp';
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_exec($ch);
$http_status_code = curl_getinfo($ch, CURLINFO_HTTP_CODE));
curl_close($ch);

これで$http_status_codeに値が格納される。

これだけで6行もかかるなぁ。
もっといいやり方ある気がするけど…

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