Friday, March 19, 2010

jQuery scroll to element

Here's a simple way to auto scroll to an element of the page really nice.

First you have to add this piece of code (of couse jQuery library must be included in your source code):

jQuery.fn.extend({
scrollTo : function(speed, easing) {
return this.each(function() {
var targetOffset = $(this).offset().top;
$('html,body').animate({scrollTop: targetOffset}, speed, easing);
});
}
});

And then you just scroll to an element id:

$('#element_id').scrollTo(1000);

You can speed up the scrolling by reducing the scroll time. Eg. scrollTo(100)

Thursday, March 4, 2010

PHP log errors to log file

Logging PHP errors to a log file is critical. You don't want to display PHP errors or warnings to users, but to log all errors to a file that you can view. This way you can fix all errors, warnings, notices and the client won't see any PHP error.

You can easily do this by adding two lines at the beginning of your code:

ini_set('log_errors', 1);
ini_set('error_log', '/path-to/error_log.file');

You can use later any editor to view contents of your log file and fix all problems that occured.

Wednesday, February 10, 2010

PHP date/time difference

I have found a great function that returns the difference in days, hours and minutes between 2 dates.

Here is the link, works like a charm:

http://www.gidnetwork.com/b-16.html

For example, this function can be used for events, to know how much time is left until the next event.