PHP

Working with JSON

A common use of JSON is to read data from a web server, and display the data in a web page. Objects in PHP can be converted into JSON by using the PHP function json_encode() in reverse you can use json_decode() To get POST JSON with PHP, you use the following Methods 1) file_get_contents # Get JSON as a string $json_str = file_get_contents(‘http://url’); # Get as an object $json_obj = json_decode($json_str); file_get_contents, this allows you to get JSON data from url. 2) cURL $ch = curl_init(); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); curl_setopt($ch,CURLOPT_URL,”URL”); curl_setopt($ch,CURLOPT_RETURNTRANSFER,1); curl_setopt($ch, CURLOPT_USERAGENT, “Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US) AppleWebKit/525.13…

Redirect Based On Referrer Or IP Address

Using PHP you can easily redirect your website visitors to a different page depending on where they come from. For example you may have 2 different web sites selling a product but only one customer care web site where people submit support tickets. Depending from which of the 2 web sites a visitor comes to that support site you may want to show them different web page. PHP stores information about the referring URL in one of its global variables – $_SERVER. You can easily access that value using the $_SERVER[‘HTTP_REFERER’]. Now what you have to do is to see…

PHP interview questions and answers for freshers – Part 1

PHP interview questions, which should help you become a best PHP codder. We hope you find these questions useful. If you are an interviewer, Take the time to read the common interview questions you will most likely be asked. What is PHP?PHP is a server side scripting language commonly used for web applications. PHP has many frameworks and cms for creating websites.Even a non technical person can cretae sites using its CMS.WordPress,osCommerce are the famus CMS of php.It is also an object oriented programming language like java,C-sharp etc.It is very eazy for learning require_once(), require(), include().What is difference between them?require()…

Top 5 Best PHP Frameworks of 2018

Talking about the PHP frameworks, they are developed to complement PHP. PHP frameworks complement PHP in many ways, some of which are: Provides pre-built modules Serves a platform for building robust & reusable components Enables faster development cycles Using libraries & tools provided by the framework results in rapid development Facilitates easy upgradations and maintenance of the developed applications Has an excellent community support Facilitates security features So basically PHP frameworks cater a basic structure to complement PHP in the above-listed ways. As these frameworks enforce the developers to use coding standards and development guidelines hence giving importance to stabilize the…

Convert Array to XML and XML to Array in PHP

XML (Extensible Markup Language) is a markup language that encodes documents in a machine-readable and human-readable format. Generally, XML is used to store and transport data. You can use XML many ways in the web application. If you’re concerned about database size and want to reduce database uses, XML can help you to free the space from the database. Instead of the database you can store the data in the XML file and retrieve data from XML file without connecting to the database. In this tutorial, we will show you how to convert PHP associative or multidimensional array to XML…