Home Blog Page 4

how to get data from api using curl in php

0
PHP cURL tutorial

Welcome back to shortlearner.com, In this post we will see how to fetch record from a website by using cURL API. so before start this tutorial we should take an small overview of it, what is it , how does it works and its benefites.

PHP cURL tutorial

What is cURL

so basically cURL means client URL which allows us to connect with other URLs and use their responses in our code, and it is a library that allows to make HTTP requests in PHP.
in order to use PHP’s cURL functions we need to install the libcurl package in our server.
PHP also requires that we use libcurl 7.02-beta and higher and it is works from PHP version 4.3.0 or higher.
in easy way cURL is a way to hit an URL from our code to get a html response from it.

Also Read
How to Install PHP on CentOS.
How to Send Attachment on mail using PHP.

PHP Login Script With Remember me.
Unable to create a directory a wordpress error

How to integrate Razorpay Payment Gateway using PHP.
Change password using javascript, php and mysqli.
Password and Confirm Password Validation Using JavaScript

Check Email is Already Registered in Database using Ajax and JavaScript.
How to hide extension of html and php file.?

Now we understand the uses of cURL with a real life example. suppose you are a owner of 5 luxuries hotel and all are registered in some kind of OTA (online traveling agent) like make my trip, goibibo and travel guru.
you want to manage all the inventory and rates on their platforms according to season.

in this case you have perform this task in 2 ways. first and difficult one is you go to each and every OTA’s dashboard and manage inventory or rates or you can try to develop a platform to manage all the hotels by using API.

so if you have a knowledge of cURL funcationlity you will manage it easily by hitting client’s URL.

In the below code we fetch the record from jsonplaceholder.typicode.com/users by using cURL functionality and print it on our webpage.

<?php 
$ch = curl_init( );
curl_setopt($ch, CURLOPT_URL, "http://jsonplaceholder.typicode.com/users");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$result = curl_exec($ch);
            curl_close($ch); 
$response = json_decode($result);
//echo "<pre>";print_r($response);echo"</pre>";
foreach ($response as $key => $row) {
	echo $row->name."<br>";
}
?>

first of all we use curl_init() function, this function is use for initializes a new session.
curl_setopt() functions is ues for set URL.
CURLOPT_RETURNTRANSFER that will return the transfer as a string of the return value of curl_exec().
and curl_close() that is using for end the session.

how to create social media share buttons

0

In this post we learn how to create social media share buttons with the help of font awesome icons , bootstrap and CSS and learn how to deploy it for any website.


so before start this tutorial we should take an small overview about fontawesome and learn the implementation process of icons.

we are living in the era of digital. we have a lots of digital platform like facebook, twitter, instagram, linkedin, whatsapp, google plus and many more.

Today most of the business and companies are holding their social account. so they can reach to their customers or client base via sharing some important and relatable contents according to their niche, and sharing all the offers and information over there.

most of the developers are uses small images of social media platform or uses favicons of also .fontawesome and glyphicons are the two third party icon providers which have a good library of favicons and easy to implement.

If we want to share this article with different type of social media platforms so this article with reach more readers than i use this .

In the below code we will learn how to add share button to website. so just copy the code and paste it to your website.

<link href="//maxcdn.bootstrapcdn.com/bootstrap/4.1.1/css/bootstrap.min.css" rel="stylesheet" id="bootstrap-css">
<script src="//maxcdn.bootstrapcdn.com/bootstrap/4.1.1/js/bootstrap.min.js"></script>
<script src="//cdnjs.cloudflare.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<!------ Include the above in your HEAD tag ---------->

<link href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.10.2/css/all.css" rel="stylesheet">
<!-- Include the above in your HEAD tag -->
<div class="container-fluid" id="cont">
	<div class="row">
		<div class="col-sm-12">
		    <div class="middle">
                <a class="btn2" href="http://www.facebook.com/sharer.php?u=<?=$site_url?>">
                    <i class="fab fa-facebook-f"></i>
                </a>

                <a class="btn2" href="https://twitter.com/share?url=<?=$site_url?>&amp;text=Simple%20Share%20Buttons&amp;hashtags=shortlearner">
                    <i class="fab fa-twitter"></i>
                </a>
<a class="btn2" href="https://plus.google.com/share?url=<?=$site_url?>">
                    <i class="fab fa-google"></i>
                </a>

<a href="whatsapp://send?text=The text to share!" data-action="share/whatsapp/share"> <i class="fab fa-whatsapp"></i></a>

  </div>
		</div>
	</div>
</div>

now we are adding some CSS to creating our button responsive and attractive. just copy the below CSS part and paste it in the head section of your html code.

#cont {
    background-color: #002147;
    padding: 100px;
}

.middle {
    text-align: center;
}
.btn2 {
	display: inline-block;
	width: 50px;
	height: 50px;
	background: #f1f1f1;
	margin: 10px;
	border-radius: 30%;
	box-shadow: 0 5px 15px -5px #ecf0f1;
	color: #3498db;
	overflow: hidden;
	position: relative;
}

a.btn2:hover {
	transform: scale(1.3);
	color: #f1f1f1;
}

.btn2 i {
	line-height: 50px;
	font-size: 20px;
	transition: 0.2s linear;
}

.btn2:hover i {
	transform: scale(1.3);
	color: #f1f1f1;
}

.fa-facebook-f {
    color: #3c5a99;
}

.fa-twitter {
    color: #1da1f2;
}
.fa-google {
    color: #dd4b39;
}


.btn2::before {
	content: "";
	position: absolute;
	width: 120%;
	height: 120%;
	background: #3498db;
	transform: rotate(45deg);
	left: -110%;
	top: 90%;
}

.btn2:hover::before {
	animation: aaa 0.7s 1;
	top: -10%;
	left: -10%;
}

@keyframes aaa {
	0% {
		left: -110%;
		top: 90%;
	}
	50% {
		left: 10%;
		top: -30%;
	}
	100% {
		left: -10%;
		top: -10%;
	}
}

this is the customization of social network sharing buttons. if you are trying to add on WordPress website than there are some best plugins that will help you.

WordPress to Buffer
Simple Social Icons
Social Icons Widget by WPZoom
WordPress Social Login
Revive Old Posts
AddtoAny

hope this article will helps you. please share this article with all your developer buddies and help them.

Preview of image before upload using jQuery

0
image preview using jquery

today in this post we will learn how to Preview of image immediately after file is selected in file upload using jQuery. In our previous post we learn how to convert a number into words.
Most of the developer use this feature in their panel and it is a good practice. A good developer always thinks about his user and he provide a user friendly UI to his clients.

image preview using jquery

To begin with this tutorial we will take an short overview of jQuery and its useful features.

Why is Used in jQuery.

jQuery is a open source and light weight library of Java script, with the help of jQuery we can develop our website or software more interactive and attractive.
we can also handle such difficult task like event handling, AJAX and animation easily with the help of jQuery.

Add Minified Jquery file

so first of all we are add jquerymin.js and jquery-ui.min.js in the head section of html code.
after adding the jQuery files we are adding and input type file which will takes the file from our local system.

after selecting the file we will call an onchange function which will takes the file and read the file and preview the image file with the help of id.
just copy the below code and run it.

<script type="text/javascript">
		function readURL(input) {
            if (input.files && input.files[0]) {
                var reader = new FileReader();

                reader.onload = function (e) {
                    $('#viewfile')
                        .attr('src', e.target.result)
                        .width(150)
                        .height(200);
                };

                reader.readAsDataURL(input.files[0]);
            }
        }
	</script>

PHP Login Script With Remember me.
Unable to create a directory a wordpress error
Change password using javascript, php and mysqli.
Password and Confirm Password Validation Using JavaScript

show image Complete code

<!DOCTYPE html>
<html>
<head>
<script  src="http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>
<script  src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.0/jquery-ui.min.js"></script>
<meta charset=utf-8 />
<title>Shortlearner Jquery Tutorial</title>
</head>
<body>
	<script type="text/javascript">
		function readURL(input) {
            if (input.files && input.files[0]) {
                var reader = new FileReader();

                reader.onload = function (e) {
                    $('#viewfile')
                        .attr('src', e.target.result)
                        .width(150)
                        .height(200);
                };

                reader.readAsDataURL(input.files[0]);
            }
        }
	</script>
  <input type='file' onchange="readURL(this);" />
    <img id="viewfile" src="#"  />
</body>
</html>

after run the above code we will see the Preview of our image before upload with the help of jQuery.

if this tutorial helps you please share it with your developer buddies, and if you want to add something new method than contact us we will updated your methods too.
keep learning ,keep coding

How to extract all URL from website in PHP

0
extract all url using php

Welcome to another PHP tutorial post. in our previous post we learn how to Get Domain Name from URL in PHP
today in this post we will learn how to extract all URL from a website with the help of predefined PHP functions like file_get_contents.

extract all url using php

so before start to fetching all URL of a website or a webpage we will take an short overview of DOMDocument.

What is DOMDocument in PHP

The PHP DOMDocument library allows us to manage HTML and XML pages after uploading our script in new DOMDocument.
so basically it is a best option to reading and changing into a HTML and XML files with the help of DOM library.

file_get_contents for reading

as we all know that file_get_contents is a predefined PHP functions which is helpful for read a content of a file into a string format.
So first of all we are creating a variable with the name of $html which will store all the string values which will converted by file_get_contents functions of PHP.

after putting the values in $html variable we are simple create a new DOM document which will Parse the HTML. The @ is used to suppress any parsing errors, that will be thrown if the $html string isn’t valid HTML.

by using DOMDocument PHP function getElementsByTagName() we will get a new instance of class DOMNodeList which contains all the elements of local tag name.
so we are passing anchor tag in side getElementsByTagName().

so in the below code we are putting our URL to fetch all the links which are inside the anchor (a) tag.

<?php 
$html = file_get_contents('http://Shortlearner.com');
$dom = new DOMDocument;
@$dom->loadHTML($html);

$links = $dom->getElementsByTagName('a');
foreach ($links as $link){
    echo $link->getAttribute('href'), '<br>';
}
?>

Also Read
How to Install PHP on CentOS.

How to Send Attachment on mail using PHP.

PHP Login Script With Remember me.
Unable to create a directory a wordpress error

How to integrate Razorpay Payment Gateway using PHP.
Change password using javascript, php and mysqli.
Password and Confirm Password Validation Using JavaScript

Check Email is Already Registered in Database using Ajax and JavaScript.
How to hide extension of html and php file.?

How to install CMake on CentOS 8

0
CMake installation on CentOS

Welcome back to another tutorial of CentOS. In our previous CentOS tutorial we learn how to install google chrome in CentOS.
Today in this post we will see how to install CMake On CentOS.

before start this tutorial we will take a short overview of CMake and CentOS.

CMake installation on CentOS

What is CMake.?

so basically CMake is a free, opensource and cross-platform family of tools designed to build, test and package the software.
It is developed by Kitware for a powerful, cross-platform build environment for open-source projects. 

Before Installation

Before start to install the CMake on our Linux machine. we must have the non-root user account on our desktop with sudo privileges.
so just follow the below steps for easy installation.

Install Latest Version of CMake CentOS

So before installing CMake we need to download its package first, and the reason behind is that because the CentOS Global Repository  does not provide us a latest version of CMake.
so no need to worry about it we will download our latest CMake package manually.

download CMake latest version

so just follow the below steps to download the latest version of CMake.
first we open the terminal by pressing ctr+alt+t in our CentOS machine.
for downloading latest package copy the below command and run it on terminal.

wget https://github.com/Kitware/CMake/releases/download/v3.15.2/cmake-3.15.2.tar.gz

after running the above command the latest package will be downloaded in .tar format. so we are extracting this package by using tar command.

tar -zxvf cmake-3.15.2.tar.gz

after extracting our CMake package we will navigate it by using cd command.

cd cmake-3.15.2

Now we are running bootstrap file by following command.

./bootstrap

After running the bootstrap command we need to Run make command

make

Now we will install CMake by below command.

sudo make install

Confirm installation and check version

Now confirm the installation and check the version by using below command.

cmake --version

So finally we learn how to install CMake in our CentOS machine. if this tutorial helps you than please support us and sharing this tutorial with your developer buddies.