PHP file_get_contents()でファイルが開けないwarningを消す方法

Warningを非表示にするだけであれば、file_get_contentsの前に「@」を付加するだけ

Warningを非表示にするだけであれば、file_get_contentsの前に「@」を付加するだけですが、ユーザーの存在の有無に応じて処理を分岐したい場合、次のようなif文で対処することができます。

○ユーザーの存在の有無に応じて処理を分岐する
<?php
$url = "https://api.twitter.com/1/users/show.json?screen_name=nisi9981";
 
if ($json = @file_get_contents($url)) {
    echo $json;
} else {
    echo "このユーザーは存在しません。";
}
?>

ネタ元