PHP Levenshtein distance

Levenshtein distance is a way of calculating how different two strings are. This function is extremely helpful in determining if a user made a mistake in entry, trying to find similar inputs, or comparing strings for any reason. The Levenshtein distance is a numeric value of how many changes are necessary to turn the one string into the other. There are default weights assigned to different operations like Capitalizing a letter or...

Read More

PHP Fatal error: Unsupported operand types

PHP is a very flexible language, but sometimes you’re not passing it what you expect. If you’re trying to do arithmetic, PHP will handle and convert pretty much anything except an array. So chances are if you get the “Fatal error: Unsupported operand types in” error, then you’re not adding two variables that you think you are. To troubleshoot simply do a var_dump(); before the operation that it is erroring out at...

Read More

Simple way to clean up filenames in PHP

Simple way to clean up filenames in PHP

If you want to make sure no silly characters are part of filenames, then you’ll want to sanitize any filenames of files you store on your server. This will make things a whole lot easier in the long run. Certain functions like file_exists(), will return false if the filename contains a %20 instead of a space, even if the file does exist and you can pull it up in your browser. Sanitation will also help if you port your system to a...

Read More

PHP’s exec Command

Some things to note about PHP’s shell execution. The syntax: exec(“command php”, $array=optional); So the first thing to note is that if you do not include the optional array, which is a pass by reference variable, that the command will not wait until it’s done executing before moving on in the PHP code. If you do include the array, it will put the output of the command into the array, unless in your command you route...

Read More