Help us understand the problem. What is going on with this article?

PHP curlでjsonとってくるヤツ

More than 5 years have passed since last update.


function getJson($url) {

  if (empty($url)) {
    $error = "Internal error";
    throw new Exception($error);

    // セッションを初期化
    $ch = curl_init();

    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt ($ch, CURLOPT_RETURNTRANSFER, TRUE);
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);

    // 転送を実行
    $json = curl_exec($ch);

    // エラー番号を取得
    $curlErrno = curl_errno($ch);
      $curlError = curl_error($ch);
      throw new Exception($curlError);

    // セッションを終了

  } catch (Exception $e) {
    echo "Exception-".$e->getMessage();

  return $json;


Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away