Category : PHP

How to remove character from a string?

Removing characters from a string is most common and frequent activities in PHP. Suppose, You have a long name, but your system does not allow to show more than 6 characters of your name. In this case, you need to keep only first 6 characters from your name. To solve this issue we use substr() function. – Solution to remove [...]

PHP function to extract components from an URL

You want to extract the protocol, domain name, path, or other significant component of a URL. Use the parse_url() function to automatically split the URL into its constituent parts. The parse_url() function is one of most useful URL manipulation function in PHP. Ita takes a parameter of a Uniform Resource Locator (URL), and splitting it into its individual components. The [...]

How to check empty string values in PHP?

As a PHP programmer most of the time you have to deal with form submission. In a form submission page, user may be submit a form without filling all required fields like user name, valid user email address or passwords. In that situation your system must show a notification message that, “user name field” is required. In another case, sometimes [...]

Simple trick to extract substrings from a string

Sometimes we need to extract a substring from a long string. Php provide a very flexible and powerful substr()function that allows you to extract a substring from a larger string. It takes three parameters: the string to be worked on, a starting index and an optional length. The starting index can be specified as either a positive integer that means [...]

Quickway to find max and min value from an array

There are lot of techniques to find max and min value from an array. But today I’m going to show an Quick way to find max and min value from an array. Hope you like it. First we take a list of numbers in an array. Then sort array list using PHP sort() function. To take minimum value we need [...]

Convert Color code from HEX to RGB using PHP

Hello friends, today I’m going to show you a cool function to convert color code from HEX to RGB. Well, most of the time we use directly color text like “red”,”green”,”yellow” and sometimes we uses color HEX code like “#FFFFFF” for white or “#0000000” for black. But If you want to use opacity property for text-shadow or box shadow then [...]

2 ways of printing an array in php

We use echo statement in PHP to output the value of an expression like a single variable. While echo is much more useful, but it’s have some limitation to print array contents. For example, while debugging a script, we needs to see not just the value of an expression, but also its type and it’s index information. So, this type [...]

Array flip and reverse in php

Flip and reverse sounds similar. Don’t mix-up them 🙂 array_flip function is useful when you only want to shift array index as array value and vice-verse. On the other hand if you want to change only array index in descending/reverse order then array_reverse function works great. Array flip convert key in to index and index in to key. $a = [...]

Easy way to parse comma separated item in PHP

Welcome Quick tips#2. Last day, in Quick tips#1 we learned How to Get Remote IP Address in PHP. Today We are going to learn about PHP Parsing. Using PHP, we can easily extract the individual elements of a comma-separated list. PHP has a great function named explode() that makes a comma-separated string list into an array of individual list elements. [...]

How to Get Remote IP Address in PHP

From today I’m going to introduce a new section called “Quick Tips” in my website. Here, I’ll share php/css/js/jQuery/WP snippets. It will be a fun. Let’s get started- Quick Tips#1: Today we are going to learn “How to Get Remote IP Address in PHP”. PHP has built-in facility to detect remote browser or IP address and other properties. These values [...]