为什么 PHP 中的 curl 在我抓取的 URL 中显示 1


Why does curl in PHP display a 1 in the URL that I grab?

我写了两个文件,一个HTML文件和一个PHP文件。我在PHP文件中使用了curl函数,我用它来获取HTML文件的源代码。

这是代码:

文件:

<html>
<head>
    <title>Pagina Youtube</title>
</head>
<body>
    <form method="POST" action="">
        <label for="valore_youtube">Inserisci il nome del video:</label>
        <input type="text" value="" name="valore_youtube" id="valore_youtube">
        <input type="submit" value="INVIA" name="INVIA">
    </form>
</body>
</html>

PHP文件:

<?php
    $curl_handle=curl_init();
    curl_setopt($curl_handle,CURLOPT_URL,"http://localhost/test/ilphp.html");
    curl_setopt($curl_handle,CURLOPT_HEADER,0);
    $html = curl_exec($curl_handle);
    curl_close($curl_handle);
    echo $html;
?>

代码显示 HTML 文件。但也显示了一个难以理解的 1 在更多作为输出,有人可以帮助我吗?

curl_exec直接输出,然后根据调用是否有效返回truefalse。当您将其输出为字符串时,这将呈现为10

您需要为 curl_exec 设置CURLOPT_RETURNTRANSFER以返回 HTML 本身。

curl_setopt($curl_handle, CURLOPT_RETURNTRANSFER, true);