Friday, 5 February 2016

Regular Expression

Introduction:

Regular expression is set of rules or predefined patterns.we can use regex for email addresses,phone numbers etc.
In php we have two sets of regular expression:

  • POSFIX regex.
  • PEARL style regex.
 

POSFIX:

POSFIX stands for Portable Operating System Interface for uniX , set of rules support by unix os.

PEARL Style Regex:


This regex structure follow the rules which use in PERL programming language.

Friday, 29 January 2016

CURL

Example:

In previous post i gave introduction of CURL now i will tell how we can create simple api system using CURL :


<?php 
//Your Website URL where You Have json response data
$url = "http://php-guidelines.blogspot.com/";    

//here we can use key for security purpose
$key ='xyzkey';

$curl = curl_init($url);
curl_setopt($curl, CURLOPT_HEADER, false);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_HTTPHEADER,
array("Content-type: application/json"));// we want in response format json
curl_setopt($curl, CURLOPT_POST, true);//our services using post method
curl_setopt($curl, CURLOPT_POSTFIELDS, $key);//enter value of post field

$json_response = curl_exec($curl); //it will execute curl statement

//get response code eg 404,505 etc..
$status = curl_getinfo($curl, CURLINFO_HTTP_CODE);
//if response is not success show a failure message with response code

if ( $status != 200 ) {
/*die("Error: call to URL $url failed with status $status, , curl_error " . curl_error($curl) . ", curl_errno " . curl_errno($curl));*/
$response=array("Response" =>$status,"Message"=>"Request Failed" );
echo json_encode($response);
die();

}

//if success show data to user
curl_close($curl);
$app_info =json_decode($json_response);
?>

Thursday, 28 January 2016

CURL

Introduction:

CURL stands for Client Url's ,using curl we can connect with different servers having multiple type of protocols like http,https,POST,PUT and many more.
We can use CURL to download files from different serves also we can create api mechanism using curl by usi authentication process, we will discuss complete example of curl api's on next post.