Programming Tips & Insights

Best PHP Books for Learning PHP Development and Programming (with MySQL)

PHP is by far the most popular and easiest to use web programming language in the world. If your goal is to enter PHP programming and development as a novice beginner and start from the very basics, these books are reviewed the best by actual readers. Some of the books contain chapters dealing with MySQL, …

Best PHP Books for Learning PHP Development and Programming (with MySQL) Read More »

JavaScript: Open or Redirect to Another Page / Site / Location

One of the most common uses of JavaScript is to redirect the user to or automatically open up another web page location. For example, when the user clicks a button, the JavaScript will redirect the user to the location selected in the drop down select menu. It’s just like the user has typed the web …

JavaScript: Open or Redirect to Another Page / Site / Location Read More »

JavaScript: Split and Divide Text String by A Delimiter

Spliting and dividing a string into several chunks is a rather basic need for text parsing. You can do it easily in PHP by the help of explode() function or preg_split(), in JavaScript, you can achieve this task by the split() string function. The following example illustrates the usage of javascript split() function to slice …

JavaScript: Split and Divide Text String by A Delimiter Read More »

How to Transfer / Move WordPress Blog from One Domain to Another

Basically, the root URL of your blog which is your domain or subdomain is changing here. Though this doesn’t seem like a sane decision considering the huge SEO impact that might fall upon your site but with HTTP 301 permanent redirection, this can still make sense in some situations. Assume you won’t change the details …

How to Transfer / Move WordPress Blog from One Domain to Another Read More »

MySQL: String Function to Replace Substring and Change Part of the Field Value

A typical case of replacing a part of the string to another substring in a database table is switching between site domains or URLs, such as when you want to transfer your WordPress blog from one domain to another. You have to change all values containing the original site URL to the new one in …

MySQL: String Function to Replace Substring and Change Part of the Field Value Read More »

PHP, MySQL: Calculate Number of Days between 2 Dates or Number of Hours, Minutes and Seconds

This is a rather common task in both PHP and MySQL, that is, to calculate and get the days distance (number of days) between 2 given dates. In PHP, to get the number of days between now and a future date / a past date: $days = abs(strtotime(“2011-11-20”) – strtotime(date(“Y-m-d”))) / (60 * 60 * …

PHP, MySQL: Calculate Number of Days between 2 Dates or Number of Hours, Minutes and Seconds Read More »

MySQL, PHP: Display MySQL table fields and data

While this may seem simple, but it’s more complicated than it may appear because you have to first decide which data (rows, fields, etc.) to be extracted or selected and in what way the data from the MySQL table are presented. But to simply read from a MySQL table for the fields and data: SELECT …

MySQL, PHP: Display MySQL table fields and data Read More »

MySQL, PHP: Store form textarea value or data to MySQL database table

To send the textarea text value in any HTML forms to the web server and store it into a MySQL table by PHP, you will need to POST the textarea data to a PHP script and then the PHP script would connect to a MySQL database to put the data into one of the tables …

MySQL, PHP: Store form textarea value or data to MySQL database table Read More »

PHP: Convert Radians to Degrees and Degrees to Radians

Radians and degrees are 2 different quantitative approaches to denote an angle, in PHP, you can convert a radian value to a degree by the function rad2reg() and a degree value to radian by the function deg2rad(): $degrees = rad2deg(‘3.1416’); // $degrees = 180 $radians = deg2rad(180); // $radians = 3.14159265359

PHP: Sort and Order Array Items / Elements / Numbers Naturally so 2 Comes before 10

By nature, a strict computer sorting algorithm would place ’10’ before ‘2’. As a result of comparison on a byte by byte basis, the first byte of the 2 strings are determined in the order that 1 comes before 2, thus placing ’10’ before ‘2’. However, in a natural sorting algorithm, ‘2’ comes before ’10’. …

PHP: Sort and Order Array Items / Elements / Numbers Naturally so 2 Comes before 10 Read More »

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.

Scroll to Top