Monthly Archives: February 2011

What is difference between setInterval () and setTimeout () ?

setTimeout execute javascript statement AFTER x interval.
For example – setTimeout(“execute_something();”, 2000);
This is execute function execute_something() after 2 seconds.

setInterval execute javascript statement EVERY x interval.
For example – setInterval(“execute_something();”, 2000);
This is execute function execute_something() in every 2 seconds.

Share

How to use Firebug within Google Chrome?

Google Chrome does not support plug-ins, there is Firebug-like too already available built within Google Chrome. That is called “Inspect element” just right click on page anywhere and click on “Inspect element” menu command. It will open a new panel like firebug. It works well for CSS debugging and you can change CSS in real time like firebug but JavaScript debugging is not very good supported.

Share

How to change date formate of twitter field “created_at”?

php coder who is reading twitter API for latest tweets want to change date/ timestamp format which is returned by ‘created_at’ key. Most of the times I use JSON based request. e. i. http://search.twitter.com/search.json?q=phpmind

These are the fields returned by above request.

Hope fully you understand how json string looks like.

Now it is time to convert date time stamp in more readable format.

echo date("l M j \- g:ia",strtotime($object->returns[0]->created_at));

Please change the date parameters if you want to play with different date formats.

If you want to use javaScript way to format dates here is very cool function.
Returned by twitter – Wed, 09 Feb 2011 02:44:36 +0000

Returned by this javaScript function, TwitterDateConverter ($object->returns[0]->created_at);
Output will be for Example “14 minutes ago”

See Image Below!


function Convert_Datetime($datetime)
{
    define("SECOND", 1);
    define("MINUTE", 60 * SECOND);
    define("HOUR", 60 * MINUTE); define("DAY", 24 * HOUR);
    define("MONTH", 30 * DAY); $delta = time() - strtotime($datetime);

    // convert

    if($delta < 1 * MINUTE)
    {
        return $delta == 1 ? "one second ago" : $delta." seconds ago";
    }
    if($delta < 2 * MINUTE)
    { return "a minute ago";
    }
    if($delta < 45 * MINUTE)
    {
        return floor($delta / MINUTE)." minutes ago";
    }
    if($delta < 90 * MINUTE)
    {
        return "an hour ago";
    }
    if($delta < 24 * HOUR)
    {
        return floor($delta / HOUR)." hours ago";
    }
    if($delta < 48 * HOUR)
    {
        return "yesterday";
    }
    if($delta < 30 * DAY)
    {
        return floor($delta / DAY)." days ago";
    }
    if($delta < 12 * MONTH)
    {
        $months = floor($delta / DAY / 30); return $months <= 1 ? "one month ago" : $months." months ago"; }
    else
    {
        $years = floor($delta / DAY / 365); return $years <= 1 ? "one year ago" : $years." years ago";
    }

echo Convert_Datetime("2015-04-1 22:10:00"); // one year ago

Share

How to auto refresh a page through JavaScript?

Here is the small JavaScript example that tells how you can use setTimeout() to auto refresh page content. You can utilize this script in games site or stock sites or anywhere you can think of.




PHPMIND – Javascript Tutorials



JavaScript Auto Refresh Page

This code will refresh you page in 6 seconds. We have used OnLoad() Event function to call our function. Note : Please don’t use a lot of auto refresh page because it is kind of annoying and your sever bandwidth will be decreasing, one way you are increasing hits to server.

Share

How to Enable CURL in WAMP?

CURL is not enabled by default in WAMP. Every php programmer have to use CURL to make remote connection.

The steps are as follows :

1) Close WAMP (if running)
2) Navigate to WAMP\bin\php\(your version of php)\
3) edit php.ini
4) Search for curl, uncomment extension=php_curl.dll
5) Navigate to WAMP\bin\Apache\(your version of apache)\bin\
6) edit php.ini
7) Search for curl, uncomment extension=php_curl.dll
8 ) Save both
9) Restart WAMP

That will solve your Curl issues.
Enjoy!

Share