Curl is the best way to get content of another website and traverse it according to your need. I already coverred PHP CURL tutorial with Examples in my previous posts. In this tutorial I will show you how to pass parameter in php curl get request
If you know wordpress a little then you notice that if you search anything on wordpress blog then it append values with blogurl/?s=value and display you search result. Just like below
Above image has query string in url and it also shows searched value in right bar input text.
We will be going to achieve exactly the same using curl.
$url = "https://www.wdb24.com/";
$dataArray = array("s"=>'PHP CURL');
PHP curl get request:
Below php code search “PHP CURL” in wdb24.com. http_build_query() function encode given string.
If you want to learn more about htpp_build_query function then visit my post 10 PHP Url Functions – Every beginner must check
$ch = curl_init();
$data = http_build_query($dataArray);
$getUrl = $url."?".$data;
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, TRUE);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($ch, CURLOPT_URL, $getUrl);
curl_setopt($ch, CURLOPT_TIMEOUT, 80);
$response = curl_exec($ch);
echo 'Request Error:' . curl_error($ch);
If you run above code to the browser then you will get output like below.
- PHP MYSQLi Object Oriented Tutorial for Beginners
- How to pass $_GET to command line arguments in PHP (with example)
- PHP get random User Agent Function
- User Registration in PHP
- Check and Uncheck all Checkbox using jQuery