pbootcms网站模板|日韩1区2区|织梦模板||网站源码|日韩1区2区|jquery建站特效-html5模板网

    1. <tfoot id='7sDON'></tfoot>
    2. <i id='7sDON'><tr id='7sDON'><dt id='7sDON'><q id='7sDON'><span id='7sDON'><b id='7sDON'><form id='7sDON'><ins id='7sDON'></ins><ul id='7sDON'></ul><sub id='7sDON'></sub></form><legend id='7sDON'></legend><bdo id='7sDON'><pre id='7sDON'><center id='7sDON'></center></pre></bdo></b><th id='7sDON'></th></span></q></dt></tr></i><div class="cawuzek" id='7sDON'><tfoot id='7sDON'></tfoot><dl id='7sDON'><fieldset id='7sDON'></fieldset></dl></div>
    3. <legend id='7sDON'><style id='7sDON'><dir id='7sDON'><q id='7sDON'></q></dir></style></legend>

    4. <small id='7sDON'></small><noframes id='7sDON'>

      • <bdo id='7sDON'></bdo><ul id='7sDON'></ul>

        使用 file_get_contents 進行良好的錯誤處理

        Good error handling with file_get_contents(使用 file_get_contents 進行良好的錯誤處理)

          <tbody id='UZ0m7'></tbody>
        1. <legend id='UZ0m7'><style id='UZ0m7'><dir id='UZ0m7'><q id='UZ0m7'></q></dir></style></legend><tfoot id='UZ0m7'></tfoot>
            <bdo id='UZ0m7'></bdo><ul id='UZ0m7'></ul>
            <i id='UZ0m7'><tr id='UZ0m7'><dt id='UZ0m7'><q id='UZ0m7'><span id='UZ0m7'><b id='UZ0m7'><form id='UZ0m7'><ins id='UZ0m7'></ins><ul id='UZ0m7'></ul><sub id='UZ0m7'></sub></form><legend id='UZ0m7'></legend><bdo id='UZ0m7'><pre id='UZ0m7'><center id='UZ0m7'></center></pre></bdo></b><th id='UZ0m7'></th></span></q></dt></tr></i><div class="8llgmh3" id='UZ0m7'><tfoot id='UZ0m7'></tfoot><dl id='UZ0m7'><fieldset id='UZ0m7'></fieldset></dl></div>
              • <small id='UZ0m7'></small><noframes id='UZ0m7'>

                  本文介紹了使用 file_get_contents 進行良好的錯誤處理的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

                  問題描述

                  我正在使用具有此功能的 simplehtmldom:

                  I am making use of simplehtmldom which has this funciton:

                  // get html dom form file
                  function file_get_html() {
                      $dom = new simple_html_dom;
                      $args = func_get_args();
                      $dom->load(call_user_func_array('file_get_contents', $args), true);
                      return $dom;
                  }
                  

                  我是這樣使用的:

                  $html3 = file_get_html(urlencode(trim("$link")));
                  

                  有時,URL 可能無效,我想處理這個問題.我以為我可以使用 try 和 catch ,但這沒有用,因為它沒有拋出異常,它只是給出了這樣的 php 警告:

                  Sometimes, a URL may just not be valid and I want to handle this. I thought I could use a try and catch but this hasn't worked since it doesn't throw an exception, it just gives a php warning like this:

                  [06-Aug-2010 19:59:42] PHP Warning:  file_get_contents(http://new.mysite.com/ghs 1/) [<a href='function.file-get-contents'>function.file-get-contents</a>]: failed to open stream: HTTP request failed! HTTP/1.1 404 Not Found  in /home/example/public_html/other/simple_html_dom.php on line 39
                  

                  第 39 行在上面的代碼中.

                  Line 39 is in the above code.

                  我如何正確處理這個錯誤,我可以只使用一個簡單的 if 條件,它看起來不像返回一個布爾值.

                  How can i correctly handle this error, can I just use a plain ifcondition, it doesn't look like it returns a boolean.

                  感謝大家的幫助

                  這是一個好的解決方案嗎?

                  Is this a good solution?

                  if(fopen(urlencode(trim("$next_url")), 'r')){
                  
                      $html3 = file_get_html(urlencode(trim("$next_url")));
                  
                  }else{
                      //do other stuff, error_logging
                      return false;
                  
                  }
                  

                  推薦答案

                  這里有一個想法:

                  function fget_contents() {
                      $args = func_get_args();
                      // the @ can be removed if you lower error_reporting level
                      $contents = @call_user_func_array('file_get_contents', $args);
                  
                      if ($contents === false) {
                          throw new Exception('Failed to open ' . $file);
                      } else {
                          return $contents;
                      }
                  }
                  

                  基本上是file_get_contents 的包裝器.它會在失敗時拋出異常.為避免覆蓋 file_get_contents 本身,您可以

                  Basically a wrapper to file_get_contents. It will throw an exception on failure. To avoid having to override file_get_contents itself, you can

                  // change this
                  $dom->load(call_user_func_array('file_get_contents', $args), true); 
                  // to
                  $dom->load(call_user_func_array('fget_contents', $args), true); 
                  

                  現(xiàn)在您可以:

                  try {
                      $html3 = file_get_html(trim("$link")); 
                  } catch (Exception $e) {
                      // handle error here
                  }
                  

                  錯誤抑制(通過使用 @ 或降低 error_reporting 級別是一個有效解決方案.這可能會引發(fā)異常,您可以使用它來處理您的錯誤.有file_get_contents 可能產(chǎn)生警告的原因有很多,PHP 的手冊本身建議降低 error_reporting:參見手冊

                  Error suppression (either by using @ or by lowering the error_reporting level is a valid solution. This can throw exceptions and you can use that to handle your errors. There are many reasons why file_get_contents might generate warnings, and PHP's manual itself recommends lowering error_reporting: See manual

                  這篇關(guān)于使用 file_get_contents 進行良好的錯誤處理的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網(wǎng)!

                  【網(wǎng)站聲明】本站部分內(nèi)容來源于互聯(lián)網(wǎng),旨在幫助大家更快的解決問題,如果有圖片或者內(nèi)容侵犯了您的權(quán)益,請聯(lián)系我們刪除處理,感謝您的支持!

                  相關(guān)文檔推薦

                  MySQLi prepared statement amp; foreach loop(MySQLi準備好的語句amp;foreach 循環(huán))
                  Is mysqli_insert_id() gets record from whole server or from same user?(mysqli_insert_id() 是從整個服務器還是從同一用戶獲取記錄?)
                  PHP MySQLi doesn#39;t recognize login info(PHP MySQLi 無法識別登錄信息)
                  mysqli_select_db() expects exactly 2 parameters(mysqli_select_db() 需要 2 個參數(shù))
                  Php mysql pdo query: fill up variable with query result(Php mysql pdo 查詢:用查詢結(jié)果填充變量)
                  MySQLI 28000/1045 Access denied for user #39;root#39;@#39;localhost#39;(MySQLI 28000/1045 用戶“root@“l(fā)ocalhost的訪問被拒絕)

                        <tfoot id='hJLmy'></tfoot>

                        <small id='hJLmy'></small><noframes id='hJLmy'>

                      • <legend id='hJLmy'><style id='hJLmy'><dir id='hJLmy'><q id='hJLmy'></q></dir></style></legend>
                          <tbody id='hJLmy'></tbody>
                          <bdo id='hJLmy'></bdo><ul id='hJLmy'></ul>
                            <i id='hJLmy'><tr id='hJLmy'><dt id='hJLmy'><q id='hJLmy'><span id='hJLmy'><b id='hJLmy'><form id='hJLmy'><ins id='hJLmy'></ins><ul id='hJLmy'></ul><sub id='hJLmy'></sub></form><legend id='hJLmy'></legend><bdo id='hJLmy'><pre id='hJLmy'><center id='hJLmy'></center></pre></bdo></b><th id='hJLmy'></th></span></q></dt></tr></i><div class="zagfqv3" id='hJLmy'><tfoot id='hJLmy'></tfoot><dl id='hJLmy'><fieldset id='hJLmy'></fieldset></dl></div>
                          1. 主站蜘蛛池模板: 苏州教学设备-化工教学设备-环境工程教学模型|同科教仪 | 小型手持气象站-空气负氧离子监测站-多要素微气象传感器-山东天合环境科技有限公司 | 贴片电容代理-三星电容-村田电容-风华电容-国巨电容-深圳市昂洋科技有限公司 | 国际船舶网 - 船厂、船舶、造船、船舶设备、航运及海洋工程等相关行业综合信息平台 | 东莞韩创-专业绝缘骨架|马达塑胶零件|塑胶电机配件|塑封电机骨架厂家 | 双齿辊破碎机-大型狼牙破碎机视频-对辊破碎机价格/型号图片-金联机械设备生产厂家 | 西安烟道厂家_排气道厂家_包立管厂家「陕西西安」推荐西安天宇烟道 | 钢绞线万能材料试验机-全自动恒应力两用机-混凝土恒应力压力试验机-北京科达京威科技发展有限公司 | 广州/东莞小字符喷码机-热转印打码机-喷码机厂家-广州瑞润科技 | 冲锋衣滑雪服厂家-冲锋衣定制工厂-滑雪服加工厂-广东睿牛户外(S-GERT) | 沥青灌缝机_路面灌缝机_道路灌缝机_沥青灌缝机厂家_济宁萨奥机械有限公司 | 酒店品牌设计-酒店vi设计-酒店标识设计【国际级】VI策划公司 | 菏泽知彼网络科技有限公司| 日本东丽膜_反渗透膜_RO膜价格_超滤膜_纳滤膜-北京东丽阳光官网 日本细胞免疫疗法_肿瘤免疫治疗_NK细胞疗法 - 免疫密码 | 求是网 - 思想建党 理论强党 | 山东PE给水管厂家,山东双壁波纹管,山东钢带增强波纹管,山东PE穿线管,山东PE农田灌溉管,山东MPP电力保护套管-山东德诺塑业有限公司 | 北京公积金代办/租房发票/租房备案-北京金鼎源公积金提取服务中心 | 布袋除尘器|除尘器设备|除尘布袋|除尘设备_诺和环保设备 | 深圳宣传片制作_产品视频制作_深圳3D动画制作公司_深圳短视频拍摄-深圳市西典映画传媒有限公司 | H型钢切割机,相贯线切割机,数控钻床,数控平面钻,钢结构设备,槽钢切割机,角钢切割机,翻转机,拼焊矫一体机 | 能量回馈_制动单元_电梯节能_能耗制动_深圳市合兴加能科技有限公司 | 临海涌泉蜜桔官网|涌泉蜜桔微商批发代理|涌泉蜜桔供应链|涌泉蜜桔一件代发 | 胀套-锁紧盘-风电锁紧盘-蛇形联轴器「厂家」-瑞安市宝德隆机械配件有限公司 | 上海小程序开发-上海小程序制作公司-上海网站建设-公众号开发运营-软件外包公司-咏熠科技 | 胶水,胶粘剂,AB胶,环氧胶,UV胶水,高温胶,快干胶,密封胶,结构胶,电子胶,厌氧胶,高温胶水,电子胶水-东莞聚力-聚厉胶粘 | 韦伯电梯有限公司| 电镀整流器_微弧氧化电源_高频电解电源_微弧氧化设备厂家_深圳开瑞节能 | 西装定制/做厂家/公司_西装订做/制价格/费用-北京圣达信西装 | 闸阀_截止阀_止回阀「生产厂家」-上海卡比阀门有限公司 | 香港新时代国际美容美发化妆美甲培训学校-26年培训经验,值得信赖! | LCD3D打印机|教育|桌面|光固化|FDM3D打印机|3D打印设备-广州造维科技有限公司 | 上海公众号开发-公众号代运营公司-做公众号的公司企业服务商-咏熠软件 | 污水提升器,污水提升泵,污水提升装置-德国泽德(zehnder)水泵系统有限公司 | 深圳激光打标机_激光打标机_激光焊接机_激光切割机_同体激光打标机-深圳市创想激光科技有限公司 深圳快餐店设计-餐饮设计公司-餐饮空间品牌全案设计-深圳市勤蜂装饰工程 | 蓝米云-专注于高性价比香港/美国VPS云服务器及海外公益型免费虚拟主机 | 安平县鑫川金属丝网制品有限公司,防风抑尘网,单峰防风抑尘,不锈钢防风抑尘网,铝板防风抑尘网,镀铝锌防风抑尘网 | 分类168信息网 - 分类信息网 免费发布与查询 | 上海防爆真空干燥箱-上海防爆冷库-上海防爆冷柜?-上海浦下防爆设备厂家? | 单级/双级旋片式真空泵厂家,2xz旋片真空泵-浙江台州求精真空泵有限公司 | 热风机_工业热风机生产厂家上海冠顶公司提供专业热风机图片价格实惠 | 【直乐】河北石家庄脊柱侧弯医院_治疗椎间盘突出哪家医院好_骨科脊柱外科专业医院_治疗抽动症/关节病骨伤权威医院|排行-直乐矫形中医医院 |