Hello friends, today I will tell you through experts tool tutorial website how you can get html source code of any website with the help of php function. So let’s go.
I will tell you the method to get the source code in 2 ways.
1. with the function of file_get_contents.
2. with the help of curl function.
1. with the function of file_get_contents.
You can get the source code of html by using file_get_contents with the function htmlentities. How this function is used with htmlentities. You are given in the example below.
<?php $data = file_get_contents("https://www.expertstool.com/border-images-use-in-css/"); $html_sourcecode_get = htmlentities($data); echo $html_sourcecode_get; ?>
2. with the help of curl function.
You can get the source code of html by using curl with the function htmlentities. How this function is used with htmlentities. You are given in the example below.
<?php $u = "https://www.expertstool.com/border-images-use-in-css/"; $ch = curl_init($u); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_BINARYTRANSFER, true); $newquery = curl_exec($ch); echo $newquery_get = htmlentities($newquery); ?>