Looking for more information on how to do PHP the right way? Check out PHP: The Right Way

Derick Rethans:
Analemmas
Mar 06, 2018 @ 16:28:20

In a new post to his site Derick Rethans talks about "analemmas" and shows how to use PHP's own DateTime handling to determine the locations of the sun at different intervals (that's what an "analemma" tracks).

Last week I listened to an The Sceptics' Guide to the Universe where the word of the week was "But as I am currently starting to update the Guide to Date and Time Programming for a second edition, I was wondering whether I could create an analemma from existing PHP functions. Unfortunately, PHP only provides functionality to calculate when the Sun is at its highest point, through date_sun_info().

He includes an example of this function in use to determine the time the sun was at its zenith. While PHP by itself can't calculate the position, Derick remembered a PHP extension he wrote that could help: php-solarsystem. He includes some code using this functionality to iterate and locate the sun via its azimuth and altitude based on his choice of location (London). The result is a CSV export of data that he then drops in to gnuplot to create the graph of the analemma during that time.

tagged: analemma sun location diagram extension tutorial datetime graph calculate

Link: https://derickrethans.nl/analemma.html

Gonzalo Ayuso's Blog:
Real-life example of Closure usage with PHP5.3
Dec 07, 2010 @ 21:31:35

Gonzalo Ayuso has posted his real-life example of closures in a PHP 5.3 application rather than some of the syntax-only based examples from several other sites around the web.

One of the new improvements in new PHP5.3 version are the Closures. Here you are a real-life example where closures are really useful for me.

His example shows how to work with a nested array of data from a SQL query and walk through it using the array_walk function and a closure as a call back. Using the "use" keyword allows it to pull in values from outside the closure's scope and process the quantity, amount and price values to calculate totals.

tagged: calculate closure reallife example feature

Link:

Daniel Cousineau's Blog:
Calculating Daylight Savings Time Boundary In PHP
Mar 11, 2009 @ 17:02:15

Daniel Cousineau has written up some timely advice in a new post to his blog. It looks at pinpointing the time boundary for Daylight Savings Time in a PHP script (when it starts and when it ends).

I had an issue recently where I needed to calculate the Unix timestamp for the daylight savings time boundaries. According to the United States Naval Observatory, daylight savings time begins the Second Sunday of March and ends on the First Sunday of November.

He looks at using the strtotime function to calculate these dates but points out some quirks - like what happens when you just give it a month or something like "second Sunday". His solution was to go back one day ("March 0" instead of "March 1") and calculating the time from there, including that first full day of March in the calculation.

tagged: calculate daylight savings time boundary march november strtotime

Link:

Developer Tutorials Blog:
Calculating date difference more precisely in PHP
Mar 11, 2008 @ 13:40:00

Hasin Hayder has posted his own response to a recent "relative time" article (showing users things like "received 2 days and 3 hours ago") with a more precise method for doing something similar:

This function is production ready and you can use it in any of your application which mainly works with these date difference. I have found it somewhere in web, just forgot the source. Thanks to the unknown author of this excellent function.

The rest of the post is the function itself that takes in the interval string (formatting), the start date, end date and whether to use timestamps or not.

tagged: date calculate precise difference timestamp function

Link:

WebDevLogs:
PHP: Calculate PI
Jan 25, 2007 @ 15:29:00

Mgccl let us know about a new bit of functionality he's worked up to calculate a higher precision value of Pi than the built-in PHP function can.

I want to release some Benchmark system can be uploaded to any web host and check how good the web hosting is. Pi (π) calculations spread widely as one of the most popular CPU benchmark system, that’s why I have created a Pi calculator that can get to the accuracy you want. For now, there is still one thing I'm not sure yet, I will explain it after show you the code.

The function is provided (that takes in the precision value you want) and a brief explanation of what it does differently and a reason why to use it over the built-in function.

tagged: calculate pi percision machins formula taylor series calculate pi percision machins formula taylor series

Link:

WebDevLogs:
PHP: Calculate PI
Jan 25, 2007 @ 15:29:00

Mgccl let us know about a new bit of functionality he's worked up to calculate a higher precision value of Pi than the built-in PHP function can.

I want to release some Benchmark system can be uploaded to any web host and check how good the web hosting is. Pi (π) calculations spread widely as one of the most popular CPU benchmark system, that’s why I have created a Pi calculator that can get to the accuracy you want. For now, there is still one thing I'm not sure yet, I will explain it after show you the code.

The function is provided (that takes in the precision value you want) and a brief explanation of what it does differently and a reason why to use it over the built-in function.

tagged: calculate pi percision machins formula taylor series calculate pi percision machins formula taylor series

Link:


Trending Topics: