Showing posts with label My Tutorials | PHP. Show all posts
Showing posts with label My Tutorials | PHP. Show all posts

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. 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)

How to Save PHP Array in Database in PHP

When we create management system or a CMS like application, we need to store a lot of configuration per user, per module etc. Multidimensional array is the best ever thing to work with in such situation. Configuration can be of two different types; searchable and not searchable. Searchable configurations are those which are used to filter a search result. For example various flags, tags, categories that we store with contents. We might need to filter contents with this flags, tags etc. No searchable configurations are like widget settings. We do not search for settings of an widget, rather we need those settings while rendering the widget.

How to read commented lines in a PHP file in PHP?

Did you ever noticed the commented lines over theme files, widget and plugin files in PHP in different CMS like wordpress etc.? These commented lines are not there just because the developer wanted to, these are most probably there as the system where the file will be used requires those lines to be there at the beginning of the file to describe the files in terms such as the name of the theme or plugin, created date, author name, last modified, version name etc. These information about the file then can later be used in the system or CMS.

This purpose can be solved in many ways, such as
  1. Using a .ini file
  2. Using a separate .php file that returns an array of information
  3. Using a array-string-array method
  4. Using .txt or any file with any or no extension
  5. Using a registration method

How to pass or use PHP array in Javascript variable?

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 is ways. For example you can use AJAX to make a request and get the PHP back in JSON format. However, why to make an AJAX call if the array is ready to be used already? Right.

If the PHP array is ready to be used in Javascript already, then just simply echo the PHP array in a Javascript variable as follows.

How to get variable value from URL query string in PHP?

We already know that we can get URL query string variable in $_GET super global array. But sometimes we might have to analyze a string which is an URL with query string and need to pull out value of a given variable from that. Also, it can be that we were given only the query part of an URL as string and we have to find out value of a given variable. Lets see how we can face this issue.

How to read the RAW version of POST data in PHP?

Well when you submit data using a form or anyway and the method is POST then you get the submitted data in a super global array called $_POST. But the data in the $_POST will be slightly modified by PHP that you sometimes, as per your requirement, may not be the exact same thing you inserted. But there is also another way you can access the data in $_POST without any modification, that is the RAW version.

Using 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 way to index matched results by name.

How to double-click & run PHP in CMD/console?

Hello everyone,

Welcome to this short tutorial on how to run PHP codes in console or CMD.

You get PHP console with your PHP setup called php.exe which generally resides in your PHP folder. I have WAMP installed in my computer so I have PHP installed via WAMP.

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.

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?

Sort dependency list or Topological Sorting in PHP

Topological Sorting - Wkipedia

In the field of computer science, a topological sort (sometimes abbreviated toposort) or topological ordering of a directed graph is a linear ordering of its vertices such that for every directed edge uv from vertex u to vertex v, u comes before v in the ordering. For instance, the vertices of the graph may represent tasks to be performed, and the edges may represent constraints that one task must be performed before another; in this application, a topological ordering is just a valid sequence for the tasks. A topological ordering is possible if and only if the graph has no directed cycles, that is, if it is a directed a cyclic graph (DAG). Any DAG has at least one topological ordering, and algorithms are known for constructing a topological ordering of any DAG in linear time.

Sometimes, we fall into situations where we have a list of tasks to be done, but with a condition that each of the tasks may need one or more tasks from the list to be done before them. Let’s, consider that we have to do tasks a,b,c,d and the condition is b & d has to be done before the task a, then the sorting will become b,d,a,c.