Author name: Yang Yang

Hello, I'm Yang. I build online businesses that please people. Want to join in and post some useful articles on Kavoir.com? Shoot me a message.

PHP: Find and Return the Minimum (Lowest) Value or Maximum (Highest) Value of Several Numbers

While you can always make your own function to take on an array of numeric values and find out the highest or lowest value from all of the numbers, PHP has got the inherent functions min() and max() for this kind of job: print min(24.4, -11, 0.3); // output: -11 print min(array(24.4, -11, 0.3)); // …

PHP: Find and Return the Minimum (Lowest) Value or Maximum (Highest) Value of Several Numbers Read More »

PHP: Differences between exec(), shell_exec(), system() and passthru()

All 3 PHP functions: exec(), system() and passthru() executes an external command, but the differences are: exec(): returns the last line of output from the command and flushes nothing. shell_exec(): returns the entire output from the command and flushes nothing. system(): returns the last line of output from the command and tries to flush the …

PHP: Differences between exec(), shell_exec(), system() and passthru() Read More »

Linux, PHP: Differences between File Modification Time: filemtime() and File Change Time: filectime()

In most Unix file systems, the modification time and the change time of a file may not necessarily be the same, they are actually 2 very distinct concepts to deal with: File modification time represents when the data blocks or content are changed or modified, not including that of meta data such as ownership or …

Linux, PHP: Differences between File Modification Time: filemtime() and File Change Time: filectime() Read More »

PHP: Exchange Array Keys and Values

To switch the position of keys and corresponding values in each element of an array, use the PHP function array_flip(): $a = array(‘1’ => ‘a’, ‘2’ => ‘b’, ‘3’ => ‘c’); $b = array_flip($a); print_r($b); And the output would be: Array ( [a] => 1 [b] => 2 [c] => 3 )

PHP: Create an Array of A Range of Characters (Numbers or Letters) or Multiple Identical Values

To create an array of a series of consecutive numbers or alphabetical letters or even any ASCII characters, you can use PHP function range(): $a = range(0, 100, 2); // $a is an array of even integers from 0 to 100. $b = range(‘a’, ‘z’); // $b now contains all lowercase alphabetic letters from a …

PHP: Create an Array of A Range of Characters (Numbers or Letters) or Multiple Identical Values Read More »

PHP: Count the Number of Occurrences of Each Unique Value in an Array

For example, you have an array of non-unique values that are student names, you know there are just 5 of them but a total of 15 elements exist in that array with some student names repeated in more than one elements. To count the occurrences of all the unique values, in this case, 5 student …

PHP: Count the Number of Occurrences of Each Unique Value in an Array Read More »

PHP: Divide and Split an Array into Chunks (Sections) or Several Sub-arrays

A big array is awkward. To divide the big array and split it into smaller sub-arrays or children arrays by size, you can use the PHP function array_chunk(): $sections = array_chunk(array(‘k’, ‘l’, ‘m’, ‘n’, ‘o’), 2); To slice $sections into smaller arrays by the size of 2, and $sections will look like this: Array ( …

PHP: Divide and Split an Array into Chunks (Sections) or Several Sub-arrays Read More »

PHP: Change Array Key Case – All Array Keys to Lowercase or Uppercase

While you can easily fabricate your own functions to do this element by element, you can simply resort to the php function array_change_key_case() to do it for you: $new_array = array_change_key_case($old_array, CASE_UPPER); Changes all the keys in $old_array to upper case and $new_array = array_change_key_case($old_array, CASE_LOWER); Changes all the keys in $old_array to lower case.

PHP: Create an Array

Array is probably the simplest compound data type every language supports. It’s basically a set of ordered values (text strings, numbers or booleans and even a child array). You can create an array in PHP by: $companies = array(‘Microsoft’, ‘Google’, ‘IBM’, ‘Apple’); Now array $companies contains 4 text string values. You can append one more …

PHP: Create an Array Read More »

Apache, PHP: Get Client Browser HTTP Request Headers Information

Every HTTP requests made by any client web browsers to an Apache should conform to the HTTP specification and provide certain set of headers information for the server to parse and understand. Useful headers information that can be retrieved in PHP by function apache_request_headers() includes: User-Agent: Operating System, browser and its version number, … Accept-Language: …

Apache, PHP: Get Client Browser HTTP Request Headers Information Read More »

Apache, PHP: Function to Get and Return PHP Version Number and Apache Version

To get the PHP version as well as the Apache version of the current host build, you will need the PHP function apache_get_version(): $ver = apache_get_version(); Sample output: Apache/2.2.6 (Win32) PHP/5.2.5 Which returns a string containing the Apache version number (2.2.6) as well as that of PHP (5.2.5). You can also get the PHP version …

Apache, PHP: Function to Get and Return PHP Version Number and Apache Version Read More »

Apache, PHP: Get Apache Enabled Modules in PHP Dynamically and Detect if a Apache Module is Installed

Sometimes you will need to detect if a certain Apache module is installed dynamically from PHP so as to determine for proper actions to take. For example, if you write inherent functionalities for optional SEO friendly URLs, you will want to know if the client host has the famous Apache module mod_rewrite installed and enabled, …

Apache, PHP: Get Apache Enabled Modules in PHP Dynamically and Detect if a Apache Module is Installed Read More »

PHP: Difference between htmlspecialchars() and htmlentities() Functions

2 functions exist in PHP to convert special characters to HTML entities (a kind of representations defined as in XML for web client such as browsers to recognize and render as special characters such as a spade: â™ , which can be represented as ♠ in HTML), namely htmlspecialchars() and htmlentities(). But what’s the difference? The …

PHP: Difference between htmlspecialchars() and htmlentities() Functions Read More »

PHP: open_basedir in php.ini to Restrict and Limit PHP File Accesses to a Certain Directory

The open_basedir directive in php.ini limits PHP file accesses (such as file opening, writing and deleting) within a designated directory such as /home/www/public_html so that it doesn’t endanger the rest of the system in any way. With proper Apache permissions and PHP installed as an Apache module, PHP inherits whatever privileges Apache has. As Apache …

PHP: open_basedir in php.ini to Restrict and Limit PHP File Accesses to a Certain Directory Read More »

Where is php.ini located?

Well it depends on the Linux distribution you are using, the version of php and the way you install it with Apache web server. Php.ini may be here: /etc/php.ini Or here: /etc/php/php.ini /etc/php5/php.ini Or here: /usr/bin/php5/bin/php.ini Anyway, you can always find any file named php.ini in this manner find / -name php.ini The simplest yet …

Where is php.ini located? Read More »

Accidental Ctrl+S Locks and Freezes Linux Terminal / SSH / Telnet

Ctrl+S happens to be a rather handy and popular combination as it’s used in Windows applications to save your current working data. I accidentally used it several times in Vim and it keeps locking the screen up and halting the interactivity — basically, after Ctrl+S I can’t do anything to the terminal (window). I use …

Accidental Ctrl+S Locks and Freezes Linux Terminal / SSH / Telnet Read More »

How to change Vim syntax highlighting colors?

Unbuntu has auto-configured Vim to use syntax highlighting for text (mostly, programs and configuration files of course) editing, the problem however, is that some of the colors appear to be darker than wanted on SSH console and it’s a little hard to recognize comfortably. So how can we change the default colors of the syntax …

How to change Vim syntax highlighting colors? Read More »

Scroll to Top