Using the preg_replace function you can easily replace all characters in a string that are not alphanumeric. This can be useful for sanitizing a string
How To Check the SHA Hash of Files
When you download software online often the publisher will also provide a file hash to make sure that the file hasn’t been modified or hacked
htmlentities() versus htmlspecialchars() – What’s Better For Emitting HTML?
Both htmlentities and htmlspecialchars work the same way in that they are used to emit a string of user input that may contain raw HTML
DOMDocument PHP Tutorial
DOMDocument function is used to parse and manipulate HTML and XML documents in PHP. Below are a few examples on how to use the DOMDocument
How to Diff Two Strings and Show the Difference in HTML
This php class will take two strings and return a html diff of them with the <ins> and <del> html tags representing what was deleted
Recursively Loop Over a Directory using RecursiveDirectoryIterator
You can use PHP’s built in directory iterator (in php 5 or 7) to loop over a directory and perform operations on the files easily.
How to Test a Date for Validity
Needed a function to test if a date was valid in PHP. This function does that but it also requires an expected date format. Example
Function to Remove Dollar Signs and Commas From a Number
I needed a function to turn a string value dollar with commas into a decimal I could insert into MySQL. This function below will take
Using pathinfo Function to Detect File Extention
Sometimes that’s not necessary to check a file’s mime type and you only need to check the file extension. To do that we can use
Function to Parse URLs From a PDF Document
You don’t have to actually programmatically read a PDF to parse out the links in them. This simple routine below will parse out all the