首页 > 解决方案 > CURL 中使用的列表中的多个 URL

问题描述

我创建了这个脚本:

<?php
    
            
        </head>
    
    <form class="form-horizontal" method="post" action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]);?>">
    <fieldset>
    
    
    <legend>Linki</legend>
    
    
    <div class="form-group">
      <label class="col-md-4 control-label" for="textarea">Linki</label>
      <div class="col-md-4">                     
        <textarea class="form-control" id="textarea" name="name">kazdy link w osobnej linijce </textarea>
      </div>
    </div>
    
    
    <div class="form-group">
      <label class="col-md-4 control-label" for="wyslij"></label>
      <div class="col-md-4">
        <button id="wyslij" name="wyslij" class="btn btn-default">Button</button>
      </div>
    </div>
    
    </fieldset>
    </form>
    
    
    
    
    
    <table>
    <?
    for ($i = 0; $i <= $count; $i++) {
    echo "<tr><td>".$lista[$i]."</td></tr>";
    }
    ?>
    </table>
    </html>

它没有像我预期的那样工作。

当我在表单中输入 url 时,它会用爆炸来切割它,并且每个 url 都设置为新的列表元素。

例如网址:

google.com 
yahoo.com 
ebay.com

创建

lista[0] -> google.com 
lista[1] -> yahoo.com 
lista[2] -> ebay.com

现在我想使用列表中的每一个 url$html = "file_get_contents_curl($lista[$i]);"来抓取og:image

但它不起作用。当我在表单中只使用一个 url 时,它会创建结果 url 以og:image从侦听的 url。当表单中有多个 url 时,结果它只显示表单中的 url。

例如它应该如何工作:

网址形式:

https://www.ebay.com/itm/NEW-HP-Stream-14-Laptop-Celeron-N3060-4GB-RAM-32GB-32-GB-eMMC-Windows-10/292593246536?_trkparms=5373%3A5000006400%7C5374%3ATech%7C5079%3A5000006400

返回:

https://i.ebayimg.com/images/i/292593246536-0-1/s-l1000.jpg

网址形式:

https://www.ebay.com/itm/NEW-HP-Stream-14-Laptop-Celeron-N3060-4GB-RAM-32GB-32-GB-eMMC-Windows-10/292593246536?_trkparms=5373%3A5000006400%7C5374%3ATech%7C5079%3A5000006400
https://www.ebay.com/itm/NEW-HP-Stream-14-Laptop-Celeron-N3060-4GB-RAM-32GB-32-GB-eMMC-Windows-10/292593246536?_trkparms=5373%3A5000006400%7C5374%3ATech%7C5079%3A5000006400

应该返回:

https://i.ebayimg.com/images/i/292593246536-0-1/s-l1000.jpg
https://i.ebayimg.com/images/i/292593246536-0-1/s-l1000.jpg

但相反,它返回:

https://www.ebay.com/itm/NEW-HP-Stream-14-Laptop-Celeron-N3060-4GB-RAM-32GB-32-GB-eMMC-Windows-10/292593246536?_trkparms=5373%3A5000006400%7C5374%3ATech%7C5079%3A5000006400
https://www.ebay.com/itm/NEW-HP-Stream-14-Laptop-Celeron-N3060-4GB-RAM-32GB-32-GB-eMMC-Windows-10/292593246536?_trkparms=5373%3A5000006400%7C5374%3ATech%7C5079%3A5000006400

如何改变它。我是 php 的新手,并在几个小时内从 Internet 上的其他脚本中创建了此代码。

标签: phplistcurldom

解决方案


for ($i=0; $i<=$count; $i++)应该for ($i=0; $i<$count; $i++)curl_close($ch);应该叫进来file_get_contents_curl。您是否确认og:image这三个网站中的每一个都存在?


推荐阅读