background preloader


Facebook Twitter

How can I echo HTML in PHP? JSON to PHP Using json_decode. PHP's json_decode function takes a JSON string and converts it into a PHP variable.

JSON to PHP Using json_decode

Typically, the JSON data will represent a JavaScript array or object literal which json_decode will convert into a PHP array or object. The following two examples demonstrate, first with an array, then with an object: $json = '["apple","orange","banana","strawberry"]';$ar = json_decode($json); echo $ar[0]; By default, objects are converted to standard objects by json_decode: How do I extract data from JSON with PHP? JSONLint - The JSON Validator. PHP Beautifier (Make it look Pretty) - Dan's Tools. Enter your messy, minified, or obfuscated PHP into the field above to have it cleaned up and made pretty.

PHP Beautifier (Make it look Pretty) - Dan's Tools

The editor above also contains helpful line numbers and syntax highlighting. There are many option to tailor the beautifier to your personal formatting tastes. When do you use PHP Beautify Often when writing PHP your indentation, spacing, and other formatting can become a bit disorganized. It is also common for multiple developers to work on a single project who have different formatting techniques. Examples The minified PHP below: foreach ($tools as $key=>$tool) { print "<a href=\"/". Becomes this beautified : Php - How to echo single value from multidimensional array when key is numeric? Fetching custom Authorization header from incoming PHP request.

Use CURL to get cookie value and set cookie value. How to get single value from php array. Use CURL to get cookie value and set cookie value. Guzzle for HTTP POST authentication and form submission with Symfony 2.0 - Pixelite. I’ve been helping out a co-worker with a small PHP library he’s working on which will eventually automate Drupal Security Advisory emails through to a central drupal “management” site, which knows about all sites that we work on, and automatically create “work requests” and allocate them to people so that we can easily track security vulnerabilities that need fixing!

Guzzle for HTTP POST authentication and form submission with Symfony 2.0 - Pixelite

The work request API was missing a vital component - creating a new work request. So that was my job. Curl is awesome(ly verbose), but Guzzle is awesomer. Session cookies and curl in PHP. This week I released a small library call CI_host_restrictions for codeigniter that allows you to configure access to controller methods by IP address(s).

Session cookies and curl in PHP

This library is useful when you need other websites or services to access your controller methods. It can be used in conjunction with authentication as another layer of security or on its own. The biggest reason to use CI_host_restrictions is when you need to expose an API, RESTful service, etc.. to another web server or network without opening up the controller/method to whole world. It can be especially valuable you need to provide access to a third party service that doesn't have any kind of authentication mechanism and rather than just relaying on security through obscurity you can can lock access to methods or controllers by IP address. The installation process in quick, light and easy. Installation You just need to copy 2 files into your codeigniter project. Use Load the config file... there are 2 ways of doing this. OR... Download. PHP setcookie() Function. cURL Requests with PHP. Introduction cURL allows transfer of data across a wide variety of protocols, and is a very powerful system.

cURL Requests with PHP

It's widely used as a way to send data across websites, including things like API interaction and oAuth. cURL is unrestricted in what it can do, from the basic HTTP request, to the more complex FTP upload or interaction with an authentication enclosed HTTPS site. We'll be looking at the simple difference between sending a GET and POST request and dealing with the returned response, as well as highlighting some useful parameters. Basics Before we can do anything with a cURL request, we need to first instantiate an instance of cURL - we can do this by calling the function curl_init();, which returns a cURL resource.

Settings Once we've got a cURL resource, we can begin to assign some settings, below is a list of some of the core ones that I set We can set a setting by using the curl_setopt() method, which takes three parameters, the cURL resource, the setting and the value. Session TimeOut during checkout. Fix `ereg is deprecated` errors in PHP 5.3. If you upgraded to PHP 5.3, chances are high you’re going to run into a few warnings or deprecated function messages.

Fix `ereg is deprecated` errors in PHP 5.3

An example is the ereg family of functions, which are gone for good, as they were slower and felt less familiar than the alternative Perl-compatible preg family. To migrate ereg() : ereg ( '\.([^\.]*$)' , $this -> file_src_name , $extension ); becomes preg_match ( '/\.([^\.]*$)/' , $this -> file_src_name , $extension ); Notice that I wrapped the pattern ( \.([^\.]*$) ) around / / , which are RegExp delimiters.