Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/290.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/apache-flex/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
PHP Twitter追随者-错误时的默认值_Php_Twitter - Fatal编程技术网

PHP Twitter追随者-错误时的默认值

PHP Twitter追随者-错误时的默认值,php,twitter,Php,Twitter,我正在使用一个PHP代码片段来显示我的Twitter追随者数量: <?php $screenName = 'photogenixlincs'; $getData = 'followers_count'; $xml = file_get_contents('http://twitter.com/users/show.xml?screen_name=' . $screenName); if(preg_match('/' . $getData . '>(.*)</', $xm

我正在使用一个PHP代码片段来显示我的Twitter追随者数量:

<?php    
$screenName = 'photogenixlincs';
$getData = 'followers_count';
$xml = file_get_contents('http://twitter.com/users/show.xml?screen_name=' . $screenName);
if(preg_match('/' . $getData . '>(.*)</', $xml, $match) !=0)
echo $match[1];
?>

我们都知道Twitter可能有点狡猾,有时候PHP代码会显示在页面上——与3位数的Twitter追随者相比,这简直是一场噩梦。有没有办法包括一个失败事件来阻止编写PHP,或者只包括一个默认的n/a(例如,如果由于任何原因无法正确加载?

抛出异常并使用try-catch