2017-04-22 61 views
0

我想要使用如何將urlencode包含到源代碼中?

http://php.net/manual/en/function.urlencode.php

但我不知道如何將我的源。我需要編碼的URL中使用

的file_get_contents

我的代碼:

 <script class="ccscript" src="https://code.jquery.com/jquery-3.2.0.min.js" type="text/javascript"></script> 
    <title>GET URL IMAGE</title> 
    <div style="width:1265px;margin:auto;"> 
    <?php 

    if(isset($_POST['ok'])){ 
     $link = $_POST['link']; 
     $source = file_get_contents($link); 
     if(strpos($source,'example.org')!==false){ 
      $pa = '#"\s><a\shref=\"(.*?)\".*?>#s'; 
     }else{ 
      $pa = '#<img\sclass.*?src=\"(.*?)\"\/>#s'; 
     } 
     preg_match_all($pa, $source, $matches); 
     echo '<div style="float:right"><textarea class="text" cols="110" rows="50">'; 

     foreach($matches[1] as $item) //GET URL 1,IMG TAG = 0 
     { 
      if(strpos($item,'http://')!==false) 
      { 
       echo $item."\r\n"; 
      } 
     } 
     echo '</textarea></div>'; 
    } 
    ?> 
    <div style="float:left;width:210px;margin-right:15px"> 
<form action="get.php" method="POST"> 
    <input type="text" name="link" size="60" /> 
    <input type="submit" name="ok" /> 
</form> 

實例網址:http://www.example.org/%E5%9F/

當我試圖讓圖像的URL,我得到此

無法打開流:HTTP請求失敗! HTTP/1.1 503服務暫時無法使用

我想我需要使用進行urlencode這樣我就可以得到圖像的URL

+0

什麼是正確的網址,而不是'HTTP :// www.example.org /%E5%9F /'? – Pharaoh

+0

就像我說的,我需要使用「file_get_contents」,如果我不對URL進行編碼,我無法獲得URL的內容! – Enuma

回答

0

試試這個:

$source = file_get_contents(urlencode($link)); 
+0

我正在嘗試使用的URL file_get_contents正在使用cloudflare ddos​​保護,我認爲這就是爲什麼我無法獲取圖像URL! – Enuma

+0

請編輯您的答案以包含一些解釋。僅有代碼的答案對未來SO讀者的教育很少。您的回答是在低質量的審覈隊列中。 – mickmackusa

相關問題