Category Archives: PHP

PHP Array Functions

PHP Array functions need no installation. These functions are the part of PHP core.

array_change_key_case — It changes all keys in an array
array_chunk — It split an array into chunks
array_combine — It creates an array by using one array for keys and other for its values
array_count_values — It counts all the values of an array
array_diff_assoc — It computes the difference of arrays with additional index check
array_diff_key — It computes the difference of arrays using keys for comparison
array_diff_uassoc — It computes the difference of arrays with additional index check which is performed by a user supplied callback function
array_diff_ukey — It computes the difference of arrays using a callback function on the keys for comparison
array_diff — It computes the difference of arrays
array_fill_keys — It fill an array with values, specifying keys
array_fill — It fill an array with values
array_filter — It filters elements of an array using a callback function
array_flip — It exchanges all keys with their associated values in an array
array_intersect_assoc — It computes the intersection of arrays with additional index check
array_intersect_key — It computes the intersection of arrays using keys for comparison
array_intersect_uassoc — It computes the intersection of arrays with additional index check, compares indexes by a callback function
array_intersect_ukey — It computes the intersection of arrays using a callback function on the keys for comparison
array_intersect — It computes the intersection of arrays
array_key_exists — It checks if the given key or index exists in the array
array_keys — It return all the keys or a subset of the keys of an array
array_map — It applies the callback to the elements of the given arrays
array_merge_recursive — It merge two or more arrays recursively
array_merge — It merge one or more arrays
array_multisort — It sort multiple or multi-dimensional arrays
array_pad — It pad array to the specified length with a value
array_pop — It pop the element off the end of array
array_product — It calculate the product of values in an array
array_push — It push one or more elements onto the end of array
array_rand — It pick one or more random entries out of an array
array_reduce — It iteratively reduce the array to a single value using a callback function
array_replace_recursive — It replaces elements from passed arrays into the first array recursively
array_replace — It replaces elements from passed arrays into the first array
array_reverse — It return an array with elements in reverse order
array_search — It searches the array for a given value and returns the corresponding key if successful
array_shift — It shift an element off the beginning of array
array_slice — It extract a slice of the array
array_splice — It remove a portion of the array and replace it with something else
array_sum — It calculate the sum of values in an array
array_udiff_assoc —It computes the difference of arrays with additional index check, compares data by a callback function
array_udiff_uassoc — It computes the difference of arrays with additional index check, compares data and indexes by a callback function
array_udiff — It computes the difference of arrays by using a callback function for data comparison
array_uintersect_assoc — It computes the intersection of arrays with additional index check, compares data by a callback function
array_uintersect_uassoc — It computes the intersection of arrays with additional index check, compares data and indexes by a callback functions
array_uintersect — It computes the intersection of arrays, compares data by a callback function
array_unique —It removes duplicate values from an array
array_unshift — It prepend one or more elements to the beginning of an array
array_values —It return all the values of an array
array_walk_recursive — It apply a user function recursively to every member of an array
array_walk — It apply a user function to every member of an array
array — It create an array
arsort — It sort an array in reverse order and maintain index association
asort — It sort an array and maintain index association
compact — It create array containing variables and their values
count — It count all elements in an array, or something in an object
current — It return the current element in an array
each — It return the current key and value pair from an array and advance the array cursor
end —It set the internal pointer of an array to its last element
extract — It import variables into the current symbol table from an array
in_array — It checks if a value exists in an array
key — It fetch a key from an array
krsort — It sort an array by key in reverse order
ksort — It sort an array by key
list — It assign variables as if they were an array
natcasesort — It sort an array using a case insensitive “natural order” algorithm
natsort — It sort an array using a “natural order” algorithm
next — It advance the internal array pointer of an array
pos — It is the alias of current
prev — It rewind the internal array pointer
range — It create an array containing a range of elements
reset — It set the internal pointer of an array to its first element
rsort — It sort an array in reverse order
shuffle — It shuffle an array
sizeof — It alias of count
sort — It sort an array
uasort — It sort an array with a user-defined comparison function and maintain index association
uksort — It sort an array by keys using a user-defined comparison function
usort — It sort an array by values using a user-defined comparison function

PHP Arrays

Arrays are sets of data; can be defined in a PHP Script. Arrays can contain other arrays inside them without any restriction, hence building multidimensional arrays. Arrays can be referred to as tables or hashes.

You can create Arrays in two different ways. The first involves using the function array. The second involves using square brackets.

First is The Array Function Method

In the array function method you create a array in the scheme of:

$foo = bar()

For example, to set the array up to make the keys sequential numbers (Example: “0, 1, 2, 3”), use:

$foobar = array($foo, $bar);

This would produce the array as follows:

$foobar[0] = $foo
$foobar[1] = $bar

It is also possible to define the key value:

$foobar = array(‘foo’ => $foo, ‘bar’ => $bar);

This would set the array as follows:

$foobar[‘foo’] = $foo
$foobar[‘bar’] = $bar

And,

Second is The Square Brackets Method

The square brackets method allows you to set up by directly setting the values.

For example:

To make $foobar[1] = $foo, what you should do is:

$foobar[1] = $foo;

The same applies for setting up the key value:

$foobar[‘foo’] = $foo;

Other Array Lessons:

Creating WordPress Multisite Network

    • Install WordPress
    • Add the following line just above /* That’s all, stop editing! Happy blogging. */
    • define(‘WP_ALLOW_MULTISITE’, true);
    • Last step enables the Network Setup item in your Tools menu.
    • Go to Dashboard => Tools => Network Setup.
    • Do as directed. It will ask you to choose from the following two network options:
  • Sub-domains — a sub-domain based network in which sub-sites use subdomains. Example: http://lamp.sangkrit.net
  • Sub-directories — a path-based network in which sub-sites use directory path. Example: https://sangkrit.net/lamp
    • If you choose sub-domain network option then you will need to generate wild card from your c-panel check this tutorial: Subdomain Network: Adding A Wild-Card DNS In DNS Server
    • Network details get filled in automatically but you are free to make changes:
  • Server Address: The domain of the URL to access your WordPress installation.
  • Network Title: The title of your multisite network.
  • Admin E-mail:  Super admin’s email address for whole network.
  • Click the Install button.
  • Follow on screen instructions.  It provides you with cold blocks to add on your site’s wp-config.php and .htaccess files and prompts you to create a directory:
  • Create a directory for media file uploads. Directory should be writable by webserver.
  • Add the specified lines to your wp-config.php file
  • Add the specified lines to your .htaccess file
    If you do not have a .htaccess file, then create it in root directory.
  • Clear your browser’s cache and login to your site.
  • From your Dashboard at the top left corner you will see My Sites menu. Now you may visit your Network Administration from My Sites => Network Admin => Dashboard.

Migrating Multiple Blogs To WordPress Multisite

  • Export content of your existing WordPress installations from Dashboard=> Tools=> Export
  • Install WordPress
  • Activate Multisite by adding define(‘WP_ALLOW_MULTISITE’, true); in your wp-config.php
  • Open Dashboard of your new WordPress installation.
  • Open Tool=> Network Setup from Dashboard and do as directed.
  • Create blog for each site you like to import.
  • Import each site’s content you exported from old installations from Dashboard=> Tools=> Import
  • Install all themes and plugins of your old site if you like and network activate them.
  • If your old installations have their own domain names then Map domains to your main site using MU Domain Mapping

Embedding RSS Feed In Your WordPress Posts And Pages

Open Your themes function.php and add the following code at the bottom:

include_once(ABSPATH.WPINC.’/rss.php’);

function readRss($atts) {
extract(shortcode_atts(array(
“feed” => ‘http://‘,
“num” => ‘1’,
), $atts));

return wp_rss($feed, $num);
}

add_shortcode(‘rss’, ‘readRss’);

Save function.php and whenever you need to embed RSS in any of your post or page write the following short code inside your post:

[ rss feed=”https://sangkrit.net/feed” num=”5″ ]

In the above give short code replace https://sangkrit.net/feed with your feed address and in num=5 replace 5 with the number of posts you like to show.

Note: Remember there is no space between [ and rss feed and num=”5″  and  so after you copy the short code; check the space, remove it (if there is some space) and then publish it.

One Command LAMP Server Installation

Installing LAMP Server

  • Open your Linux Terminal.
  • Type: sudo apt-get install lamp-server^
  • Press Enter

Checking the Installation

  • Open a web browser
  • Type: http://localhost/
  • If your browser shows the message: “It Works” then you have successfully installed LAMP

Tasksel Method

Other than the above given method you may use the Tasksel method for installing LAMP server. Use following given commands on your Linux Terminal:

sudo apt-get install tasksel
sudo tasksel install lamp-server

PhpMyAdmin

If you need to install PhpMyAdmin for managing your website’s database:

sudo apt-get install phpmyadmin

How Automattic Makes Money

WordPress is Free, Opensource and Priceless software from Automattic used for creating website, blog or something like that. You can download WordPress from www.wordpress.org for free.

But you know how Automattic makes money as it gives everything for free. No, it don’t give everything for free but yes most of its applications and the core software WordPress is absolute free for you.

Now lets see how WordPress makes money:-

VIP Hosting

WordPress provides VIP Hosting for major brands like Time Magazine, NewYork Times, CNNBoing Boing and also TechCrunch etc. To know more brands hosted on WordPress VIP Hosting CLICK HERE

WordPress offers you two types of VIP hosting:-

Akismet Anti-Spam Technology

Akismet is an automated spam killer used by millions of blogs. Using this you don’t need to spend long time on deleting spam. WordPress makes money through Akismet as it offers different plans to bloggers for use Akismet.

For using Akismet you have to signup by choosing one of the following plans to get an API key:

  • Enterprise: Costs $50/month. Here you get multiple site access. It is good for companies having low web traffic.
  • Pro: Costs $5/month. It gives single site access. Good for small non-personal sites and blogs.
  • Personal:  Costs $0 to $120/year. Good for non-business personal blogs.
  • High Volume: Companies with or over 100k calls per month pays per call. Costs $100/month minute.

Premium Features

These are the optional priced per year upgrades offered by WordPress:

  • Be the master of your domain: Costs: $13.00 – $25.00/year. For controlling your online identity you may add your own domain name. Like www.example.com instead of www.example.wordpress.com This feature can be added to you existing WordPress blog.
  • Extra Storage: Costs $20.00 – $290.00/year. This is used by the bloggers whose content is running out of space.
  • Custom Design: Costs $30.00/year. Bloggers use this to customize blog’s fonts with a point-and-click interface. No coding required.
  • VideoPress: Costs: $60.00/year. Uploads your videos, get them converted into different formats including HD etc. Including many more features.
  • Go Ad-Free: Costs $30.00/year. Time to Time WordPress displays Ads on your blog for logged out users. You may turn off the Ads by using this feature.
  • Guided Transfer: Costs $129.00 . This feature is used for transferring a WordPress site.
  • Premium Themes: You may upgrade to premium WP Themes for adding more options to site customization. Pricing for each theme is displayed under the theme on your dashboard.

Google AdSense 

This is what most of us use to make money online by putting Google Adsense on our web content. This is a free program by Google that empowers online publishers to earn revenue by displaying some Ads on their content. As I had already told you that time to time WordPress displays Ads on your blog for logged out users, this is what Google Adsense.

Support Networks

If support forums aren’t enough to solve your problem then you may switch to support networks.

VaultPress

This is WordPress’s security, backup and support. It backup you blog automatically without any security flaw.

Plans and Pricing follows:

  • Basic: Costs $15/Month per site. Gives realtime backup and automatic restore during disaster.
  • Premium: Costs $40/Month per site. Gives back-up restore and continuous security scan.
  • Enterprise: Costs $350/Month per site. Gives solutions for large scale WordPress Installations.

Poll Daddy

This is Online Survey Software with both free and paid plans as follows:

  • Free: This is absolute free for ever not a trial or something like that.
  • Professional: Costs $200/Year.
  • Corporate: Costs $899/Year