How a config.php file can be your best friend


How a config.php file can be your best friendI use a config file in almost every PHP applications I write. Essentially I create an array called $config and setting everything I would like to be able to quickly change. For example: app name, full path to app, full url to app, development or production mode, even mysql settings.... [More]

Analyzing PHP Code


Analyzing PHP CodeThere are a number of ways to analyze php code to get a better feel for how complex it is and clues for what it may take to work on it. For example the following linux shell command will tell you how many lines of php code there is in... [More]

Get a list of whats installed on your linux box


Get a list of whats installed on your linux boxI run Ubuntu on my laptop. Every so often it is better to start over by reinstalling from scratch. I needed an easy way to keep track of what I had installed. This way when I set up the new system I can just go through the list, line by... [More]

Checking MySQL for duplicate content


Checking MySQL for duplicate contentA number of the sites I manage run a custom CMS written from the ground up. A problem I ran into recently for one of my larger sites with over 5,500 content items is how to check if a new item might be a duplicate before its added. The solution... [More]

Storing an array in MySQL from PHP


Storing an array in MySQL from PHPThere has been a number of times I wanted to store an array in a database. There was no need to split the data up and save it into individual cell. Maybe it was just debugging data or I wanted to store all the extra stuff a payment processor returns.... [More]

Using PHP StrToTime to work with dates


Using PHP StrToTime to work with datesThere are many ways in PHP to work with dates. My favorite is StrToTime, because I can store the long number (Unix Timestamp) representing the number of seconds since Jan 01, 1970 in the database. Then its easy to format it in any which way I like. Maybe one place... [More]

Ensuring a string is only text no HTML or other code


Ensuring a string is only text no HTML or other codeThis is a common problem I run it to when scrapping websites for content or even dealing with user submitted text. I ran into problems using striptags() not removing everything and general formatting errors. As a result I came up with this function to assist in the process. function clean_text($str)... [More]

Want to see your php errors?


Want to see your php errors?Are you having trouble testing and debugging your code? Would you like to see your php error messages in your browser? Here's how you can turn on php errors; add the following code to the top of your php script.ini_set('display_errors', 1); ini_set('display_startup_errors', 1); error_reporting(E_ALL); If you also want to see... [More]
1