久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

    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="qwawimqqmiuu" 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="qwawimqqmiuu" 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 進行良好的錯誤處理的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)吧!

                  問題描述

                  我正在使用具有此功能的 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() 是從整個服務(wù)器還是從同一用戶獲取記錄?)
                  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="qwawimqqmiuu" id='hJLmy'><tfoot id='hJLmy'></tfoot><dl id='hJLmy'><fieldset id='hJLmy'></fieldset></dl></div>
                          1. 主站蜘蛛池模板: 欧美大片黄 | 男女羞羞视频免费看 | 亚洲国产成人精品久久久国产成人一区 | 在线成人av | 亚洲精品久久久久久一区二区 | 国产精品国色综合久久 | 欧美日韩在线成人 | 日韩精品一区二区三区四区视频 | 北条麻妃99精品青青久久主播 | 99久久久久久久久 | 精品在线看 | 欧美日韩在线播放 | 久久免费资源 | 91国内外精品自在线播放 | av免费在线观看网站 | 暖暖日本在线视频 | 久久久久久亚洲精品 | 欧美一级片在线 | 欧美性一区二区三区 | 午夜国产精品视频 | 亚洲精品一区二区三区在线观看 | 看羞羞视频| 国产一区二区三区视频免费观看 | 精品久久久久久久久亚洲 | 99精品国产一区二区三区 | 亚洲一区av在线 | 亚洲欧美中文日韩在线v日本 | 国产性色视频 | av在线免费播放 | 久久夜视频 | 国产精品91久久久久久 | 国产精品美女久久久 | 国产91丝袜 | 日本在线一区二区三区 | 国产精品久久久久久久久免费樱桃 | 亚洲成人av一区二区 | 欧美一区二区三区在线 | 亚洲一区二区三区在线 | 久久久tv | 欧美国产精品 | 精品九九九 |