0

I want to get some website source code into webpage as result using php.

Here is my html code.i want to add php code to checkout website source code as result.

<html>
<head>
    <meta charset="utf-8">
</head>
<body>
    <center>
        <form method="post">
            <h1>Website source code</h1>
            <input type="text" name="url" placeholder="Website Url"><input type="submit" value=">>">
        </form>
    </center>
</body>
</html>

Here is my php code to export html source code.

[[-- <?php $all_lines = file('example.com/'); 
foreach ($all_lines as $line_num => $line) { 
    echo "Code.-{$line_num}: " . htmlspecialchars($line) . "\n"; 
} ?> --]] –
jwpfox
  • 5,124
  • 11
  • 45
  • 42

1 Answers1

0

If you want to get the HTML source code of an URL, you can use cURL :

<?php
$ch = curl_init("http://www.example.com");
$html= curl_exec($ch);
curl_close($ch);
echo htmlspecialchars($html);
?>

more info here cUrl - getting the html response body and here php: Get html source code with cURL

Flo
  • 356
  • 1
  • 11