PHP Tricks

Short tutorials on how to add useful enhancements to your website with some PHP code, and snippets of code I found interesting.

A representative image for the article Automatically incrementing YEAR in the copyright notice - © 2024 Automatically incrementing YEAR in the copyright notice - © 2024
A one liner that you can append to the code of your website's footer to avoid the need of manually updating the year every year (includes JavaScript alternative solution for static html pages).
A representative image for the article Assigning results of the PHP echo statement(s) to a value of a variable Assigning results of the PHP echo statement(s) to a value of a variable
Once in a while you might realize that you wish your code snippet which uses many echo statements had saved the output into a variable, instead of displaying it; it's when output buffering comes to rescue.
A representative image for the article Elegantly Using Switch in Place of a Long IF Conditional Expression Elegantly Using Switch in Place of a Long IF Conditional Expression
When you have a need to check for multiple possible values in a single variable, often the switch conditional is a preferred alternative to a long if ((...) || (...) || (...) ...) conditional expression.
A representative image for the article Validating User Input With the filter_var() Function Validating User Input With the filter_var() Function
The article demonstrates how to validate email, URL, integer, and decimal number and includes a snippet of code that would be used in a production script.
A representative image for the article An Automated Way to Add HTML Title and Meta Tags to Help SEO for a Database Driven Website An Automated Way to Add HTML Title and Meta Tags to Help SEO for a Database Driven Website
In this tutorial I show how to filter the existing page related content to generate and fill the following html tags:
<title>...</title>
<meta name="description" content="...">
A representative image for the article Using a Recursive Function to Traverse a Directory Tree Using a Recursive Function to Traverse a Directory Tree
In this tutorial I'll show you how to use a function that calls itself to scan a directory tree and output its contents.
A representative image for the article Making the code from the book
Beginning
PHP and MySQL
E-Commerce
From Novice to Professional run in 2021
Making the code from the book Beginning PHP and MySQL E-Commerce From Novice to Professional run in 2021
In this, step by step guidance, you'll see how a few adjustments to the original code that goes with the venerable book by Cristian Darie and Emilian Balanescu, published in 2008 will bring the shop to life with a much newer version of PHP and MySQL.
A representative image for the article Saving Some Time by Autoloading PHP Classes Upon Demand Saving Some Time by Autoloading PHP Classes Upon Demand
Here I'll show you how to utilize the spl_autoload_register() function from the Standard PHP Library (SPL) that helps to avoid manually including files that contain object oriented class definitions.
This page was last updated on March 02, 2021
No comments have been posted so far
Leave a Comment