使用PHP将HTML代码从url复制到另一个文件

时间:2013-01-23 02:59:52

标签: php file

我有以下PHP代码:

<?php
    $htmlFile = file_get_contents(http://archi-graphi.com/arcancianev/sejour-29-eau_turquoise_en_corse.html');
    $pdfHtml = ('pdfFile.html');
    copy($htmlFile, $pdfHtml);
        // Now you can choose to run a check to see if the new copy exists,
        // or you have the option to do nothing and assume it is made
        if (file_exists($pdfHtml)) {
            echo "Success :  has been made";
        } else {
            echo "Failure:  does not exist";
        }
?>

但是我收到了错误消息Warning: copy( <!DOCTYPE html> <html lang="fr"> <head> <meta charset="utf-8" /> <title>Vacances Arcanciane</title> ...我不知道是什么错误。任何人请帮助我,谢谢。

2 个答案:

答案 0 :(得分:3)

如果我错了,请纠正我,但你可能正在寻找file_put_contents而不是copy

<?php
    $html = file_get_contents('http://archi-graphi.com/arcancianev/sejour-29-eau_turquoise_en_corse.html');
    $pdfHtml = 'pdfFile.html';

    // this is probably what you're trying to do
    file_put_contents($pdfHtml, $html);

        // Now you can choose to run a check to see if the new copy exists,
        // or you have the option to do nothing and assume it is made
        if (file_exists($pdfHtml)) {
            echo "Success :  has been made";
        } else {
            echo "Failure:  does not exist";
        }
?>

答案 1 :(得分:-1)

检查副本的变量顺序。应该是copy($pdfHtml, $htmlFile);而不是copy($htmlFile, $pdfHtml);