Ideally, you will be using php.ini to display errors in php. However, sometimes you don’t have access to it, and you need some instant gratification now! Include this snippet in your page, and it will display the errors inline, as well as save them to a file in your current directory called “error_log.txt”.

ini_set('display_errors', 1);
ini_set('log_errors', 1);
ini_set('error_log', dirname(__FILE__) . '/error_log.txt');
error_reporting(E_ALL);

Now isn’t that just special?
The source: php display errors

Great PHP Date Reference

May 20th, 2008

Just thought we’d give some trackback attention to a much deserved reference page.

This reference gives one of the best explanations for addition of and subtraction using PHP’s built-in Date Function. Also, easily compute days in the future, past, etc using the simple natural language capabilities in the strtotime function:

PHP Dates, addition, future dates, using strotime

Special thanks to the guys/girls over at Art of Web

Additional PHP Date Functions

If you’re too lazy to even look at the link above, here are some of our useful PHP Date functions:

Convert MySQL Date to PHP Date Object

It is really almost redundant to create a function for it, but this will give you the idea. Also - this will return a date in php’s native unix format - Not human-readable format, you will have to convert it to the format you would like it after running this function.
function mysqlDateToPhpDate($mysqldate){
return strtotime($mysqldate);
}

Get Current Date (mysql format)

You use this function to save the current date to a mysql database.
date("Y-m-d H:i:s");

Convert to Mysql Format

You use this function to save date to a mysql database.
function toMysqlDate($somedate){
return date("Y-m-d H:i:s",$somedate);
}

Get Current Date (human-readable format)

date('m/d/y h:i a');

Get Next Year’s Date (in mysql format)

date((date("Y")+1)."-m-d H:i:s");

Add A Year to Date (not today)

Returns in Mysql Format (YYYY-mm-dd):

function addYearToMysql($somedate){
return date((date("Y")+1)."-m-d H:i:s",$somedate);
}

Is MySQL Date Passed

Pass a mysql date into this function to find out if it has passed.
function isDatePassed($somedate){
if(strtotime($somedate) > time())return false;
else return true;
}

My gosh, I have struggled with this conversion too many times! I shall endeavour to put an end to my troubles and anyone else’s who develops across all the layers.

The Problem: PHP is outputting the value of a textarea within javascript, which in turn is causing the javascript error “unterminated string literal…”

The Long Answer: Line Breaks, Carriage Returns, and Newline characters have different character representations depending on which language you’re in, and more so - how the character is being displayed. It seems when you pull a newline character from a mysql db, and display it in php it is displayed in ASCII format. I, myself am not all too familiar with it, but I do know it seems to be the format that the db stores data. Check out this ascii conversion table to see what all of our html characters translate to in ascii.

The Short Answer: You need to convert your ascii line breaks (both Line Break “\n” & Carriage Return “\r”) to javascript line breaks:

Solution:

$escaped_value = str_replace(chr(13),'n',$report[$column_name]);
$escaped_value = str_replace(chr(10),'',$escaped_value);

Explanation: In the first line, we use str_replace to convert chr(13) to javascript line break “\n”. Then in the second line, we convert the other possible line break (or carriage return) chr(10) to nothing (so as to prevent duplicate line breaks).