get_the_ID()

1459870313php-logo-svg

get_the_ID() is a php function in WordPress. It retrieves the Post ID for a particular post. In WordPress, each post has a unique ID. There may be situations when you need to apply an action to a specific post. This can be done by using the get_the_ID function.

For Example,

if (get_the_ID() )=212 { ?>

Steps

<?php } ?>

Advertisements

PHP-Array_unique method

Array_unique is a method in PHP which is used to display unique elements in an Array. It removes duplicate elements. The method takes the array as an Input and returns an array that contains only unique values.

Array_unique($array)

 Keep in mind that the array will not re- position the elements after it removes duplicates. 

For example-

$arr=$array (1,2,2,3);

In this array, $arr [0]=1 ,  $arr[1]=2,  $arr[2]=2, $arr[3]=3

Then, if we apply the method to this array.

$arr=Array_unique ($arr);

We get an array which has elements-

 $arr[0]=1,  $arr[1]=2 and $arr [3]=3;
There will be a null element at index 2, since that element was removed. So the element which was at index 3, will still remain at 3 and it would not re position itself to index 2.

PHP strstr function 

This function in PHP takes a string  and a token as an Input and it outputs the part of the string before the occurrence of the token.

For example

Let’s say there is a string 

$word=”Handle”

and we have a token ‘l’

Then strstr ($word, ‘l’,true); would return “Hand” as the output.

Reasons for Upgrading PHP Version

There have been times where you might have observed that your PHP code does not run simply because the plugin or application requires a later version of PHP. The PHPMailer class hosted in Github supports only PHP versions from 5.3 onwards. Now why are applications forcing us to upgrade?

There are many reasons why one should upgrade to a later version of PHP-

Reasons

Security: Older Versions are not supported with Security updates. This makes your web application in secure. For folks using PHP 5.4, the support for that version officially ended on Sept 2015.

For every stable version released by Zend Technologies (The company which develops ad supports PHP), it has an active support for two years followed by one year of support based on an as-needed basis. So, it is always advisable to upgrade to a stable release of PHP. The current stable versions are PHP 7.0.5 and PHP 5.6.20

PHP Accelerator: There is no need to run a PHP Acclerator like APC to improve performance. From PHP 5.5 onwards, opcode cache is integrated with PHP which helps in improving the performance of the site.

New Features: PHP 5.5 added a finally block to the already existing try-catch block. The finally block always gets executed irrespective of whether there is an exception in the program or not.

Built in Webserver: They have come into existence since PHP 5.4 . It serves as a reliable way of testing your PHP Application before deploying it live on the web.  Previously one would have to set up a virtual host on the local web server and test it. Installing and configuring the virtual host was something one would not like to do as a source of enjoyment!

Password Hashing:  Improved encryption mechanisms for protecting passwords.

 

Even after such compelling reasons, there are many people who still don’t upgrade. The reason being that doing an upgrade would cause a break in the application code since it relies on older features. This is in fact quite true. Unlike major programming languages like Java, PHP is not backward compatible and hence newer versions of PHP do not support older code.

Performing an Upgrade

Now, there are many ways  one could perform an upgrade. People using web hosting sites like Hostgator would find this helpful

http://support.hostgator.com/articles/cpanel/php-configuration-plugin

And for the ones coding in Linux/ Ubuntu can look at this

http://askubuntu.com/questions/565784/how-do-i-upgrade-php-version-to-the-latest-stable-released-version

 

Here are some other links for those Interested in further reading-

  1. http://php.net/supported-versions.php
  2. http://php.net/eol.php
  3. http://www.sitepoint.com/multiple-websites-apache-virtual-hosts/
  4. http://stackoverflow.com/questions/4693575/is-php-5-3-backwards-compatible-with-php-5-2
  5. Evolution of PHP
  6. https://github.com/PHPMailer/PHPMailer
  7. Zend Website