.
PHP is a server-side scripting language that was developed to create dynamic websites. In recent years, as content management systems such as Joomla!, WordPress, and Drupal are becoming more and more prevalent, PHP has since become the backbone of the web. Listed below are a few PHP snippets that can be of use to any website.
buy cheap generic viagra
The Date function has a myriad of options to give you any date combination you require for your website. It can be used in many places, but two prime examples are for displaying the current date or displaying the copyright date.
Syntax: <?php date(); ?> Usage: <?php echo date(‘Y’); ?> will return: 2011
Basic formatting characters:
d – Two digit representation for the current day with leading zero (01 to 31)
D – Three letter representation for the current month (Sun to Sat)
j – One to two digit representation for the current day without leading zero (1 to 31)
Y – Four digit representation of the current year (2011)
For an example on how to display your website copyright to and from date, you would have to use a combination of echo and concatenation: <?php echo ‘Copyright 2005-’ . date(‘Y’); ?> Which would display: Copyright 2005-2011 (or whatever the current year happens to be).
buy cheap generic viagra
The str_Replace function stands for String Replace. It replaces all occurrences of the searched for string with a replacements of another string. This can be particularly useful when reading Excel spreadsheets or XML files and needing to replace an ampersand symbol (&) with the correct XHTML syntax of “&”.
Syntax: <?php str_replace($search, $replace, $subject); ?> Usage: <?php str(replace(‘&’, ‘&’, $string); ?>
buy cheap generic viagra
The include function simply includes a file based on the given path. After it is called, any information within the file is then able to be used and displayed.
Syntax: <?php include(); ?> Usage: <?php include(‘file.php’); ?>
If file.php had variables containing information in it, they would now be able to be called, or if there was text or HTML in the file, it would automatically be displayed. This is particularly useful when you want your pages, for instance, to have a navigation section. Instead of having to change the navigation in every single page, any time the navigation is changed on the website, you would just have to change it in the “navigation.php” and it will dynamically change on every page where it is called.
buy cheap generic viagra
The array function is one of the most used in PHP. It is pretty useful whether manually inputting data in or breaking up an Excel spreadsheet. The array works by essentially creating a map and making associations between its values and keys. The key can only be an integer or a string while the value can be a value of any type.
Syntax: <?php $arr = array(1 => ‘Against’, 2 => ‘The’, 3 => ‘Grain’); ?> Usage: <?php echo $arr[1]; ?> which will produce: Against.
In the usage example, the PHP script echos the contents of the first position in the $arr array. If you wanted to echo the third position, you would simply replace the [1] with [3].