web analytics

How to read and write INI files in PHP?

how to read and write ini files in php

INI Files

INI files are simple text files with a basic structure consisting of sections, property and value. The INI files can be used across different platform which is a great advantage as a single INI file can be used in various versions of the same application for various platforms.

INI files are used to store configurations for applications in a manner of property = value. Values can be single or one dimensional array. Also sections can be used to group same type of configurations. The last thing is comments, we can write comments in INI files. Comments in INI files starts with ; (semicolon)

Read more

How to Save PHP Array in Database in PHP?

How to Save PHP Array in Database in PHP

We will see how we can store PHP array in database. We will store the php array in database and we get it back, as PHP array.

When we create management systems or applications such as CMS, we need to store a lot of configurations per user, per module etc. Multidimensional array is the best ever thing to work with in such situations. Configurations can be of two different types; searchable and non-searchable.

Read more

How to read comment blocks into PHP array?

how to read commented lines into array in php

Did you ever notice the commented lines over theme files, widget and plugin files in PHP in different CMS like WordPress etc.? These comment blocks are not there just because the developer wanted to. These lines can be there as the system may require those lines to describe the file in terms such as the name of the theme or plugin, create date, author name, update date, version number etc. These information about the file then can later be used in the system or CMS.  

Read more

How to pass or use PHP array/variable in JavaScript?

how to pass or use php array or variable in javascript

Multidimensional PHP arrays are similar to multidimensional JSON objects. So shouldn’t be there a way to use a multidimensional PHP array in Javascript? Obviously, and there are ways. For example you can use AJAX to make a request and get the PHP array back in JSON format. However, why to make an AJAX call if the array is ready to be used already? Right.  

Read more

How to use Group Names in PHP preg_match() regex to index matched results by names instead of numeric values

Using regular expressions is a very effective way to find a sub-string or all matched sub-string from a given string or text. But when you call them they give you matched results in a array with numeric indexes which is not helpful enough to get your data out of the matched results. Following is the … Read more

How to download image from URL using PHP? 2 methods explained.

Hello everyone, welcome to this short tutorial on how to download image from URL and save it on your server using PHP. Method 1: $url_to_image = ‘http://oleaass.com/wp-content/uploads/2014/09/PHP.png’;$my_save_dir = ‘images/’;$filename = basename($url_to_image);$complete_save_loc = $my_save_dir . $filename;file_put_contents($complete_save_loc, file_get_contents($url_to_image)); To download image from URL here $url_to_image is the URL of the image you want to download and $my_save_dir is … Read more

Why and How to use static properties in PHP? OOP in PHP.

A static keyword is very important in object oriented programming. Static methods and properties play a vital role in application design and also in design patterns. So what are static methods and properties? In general, to access any properties or method of a class we first have to initialize an object of that class. Then … Read more