我正在尝试使用


  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/

当我尝试获取图片网址时,我得到了


  无法打开流:HTTP请求失败! HTTP / 1.1 503服务暂时不可用


我认为我需要使用urlencode,这样我才能获取图片网址

最佳答案

尝试这个 :

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

关于php - 如何将urlencode包括在内?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/43562916/

10-09 18:12
查看更多