PHP Tricks
Short tutorials on how to add useful enhancements to your website with some PHP code, and snippets of code I found interesting.
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 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).
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.
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.
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.
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.
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.
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.
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:
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="...">
<meta name="description" content="...">
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.
In this tutorial I'll show you how to use a function that calls itself to scan a directory tree and output its contents.
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.
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.
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.
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