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

TutsPlus.com:
Formatting the Current Date and Time in PHP
Sep 26, 2018 @ 15:56:18

On the TutsPlus.com site they've posted a tutorial (by author Monty Shokeen) covering the use of PHP's built-in functionality to format date and time values such as the current date.

You'll often want to work with dates and times when developing websites. For example, you might need to show the last modified date on a post or mention how long ago a reader wrote some comment. You might also have to show a countdown of the days until a special event.

Luckily, PHP comes with some built-in date and time functions which will help us do all that and much more quite easily.

The tutorial starts with the basics of datetime handling in PHP, making use of the date function to get formatted output of either the current time or the timestamp provided. Several code examples are provided showing the output for month/day/year and hour/minute/second combinations. Next they look at how to get the current Unix timestamp, using that to calculate day differences and working with relative time strings.

The tutorial ends with a look at the DateTime functionality also included in PHP and provides several examples of it in use for both formatted date output and calculating time differences.

tagged: datetime date time formatting calculation tutorial

Link: https://code.tutsplus.com/tutorials/working-with-date-and-time-in-php--cms-31768

SitePoint PHP Blog:
Are Bitwise Operators Still Relevant in Modern PHP?
Aug 22, 2017 @ 16:16:47

In a post to the SitePoint PHP site editor Bruno Skvorc wonders if bitwise operators are still relevant in modern PHP development.

Many of you probably scratched your heads reading this title. “Bitwhat?”

In this article, we’ll look at what bitwise operators are, and whether or not their use is still relevant in this modern age of computing.

He starts off by illustrating a common use case for the bitwise operators in evaluating user permissions. He first proposes doing things on the database side, creating tables for double or single joins that could get us the information we need. He also shows an approach for what he calls a "column stampede": adding a new column to the user table when a new permission is needed. Instead he proposes the bitwise option, first explaining how values are stored and then showing how with a single value, you could potentially store all of a user's permissions in one field. Next he shows how to perform the select to determine of a user has a set of permissions and how to store them when making an insert/update.

tagged: bitwise operator modern development permission calculation tutorial

Link: https://www.sitepoint.com/bitwise-operators-still-relevant-modern-php/

SitePoint PHP Blog:
PHP Job Interview Task: Day of Week Calculation
Jan 09, 2014 @ 18:14:56

Sometimes during an interview it's difficult to determine the skill set of the person on the other side of the table. One solution to this that's become popular is asking the developer to perform a task of your choosing and watching how they work out the problem. In this new post to the SitePoint PHP blog Bruno Skvorc shares one suggestion for this kind of test - a day of week calculation.

Not so long ago, I was given a job interview task. I was to write a function which deduces the day of the standard 7-day week of ANY calendar (even an imaginary one), provided I know how often leap years happen, if at all, how many months their year has, and how many days each month has. This is a fairly common introductory job-interview task, and in this article I'll be solving and explaining the math behind it.

His task was, given any kind of calendar definition (not necessarily the Gregorian), figure out what day of the week a certain month/day/year combination would fall on. He walks through the entire code to solve the problem, including a bit to output the resulting calendar to an HTML table for each month.

tagged: interview task dayofweek calculation tutorial

Link: http://www.sitepoint.com/php-job-interview-task-day-week-calculation

Tobias Schlitt's Blog:
Randomized Pi calculation
Apr 02, 2007 @ 15:04:00

Since there is no "magic variable" to get a value for Pi in an application, Tobias Schlitt offers up the next best thing - his homegrown solution for creating the value (using a randomized variation).

I don't know which is the most common way to calculate Pi in computer programs, but from the stochastics book a read for my recent stochastics exam, I have a randomized variation, which is quite cool I think.

The code example is included along with a bit of explanation for those not familiar with the concepts behind it. It uses two of PHP functions, pow() and mt_rand(), to run through a series of iterations and, using a preset precision value, find the "hits" to finally calculate the value at the end.

tagged: randomize pi calculation pow mtrand precision randomize pi calculation pow mtrand precision

Link:

Tobias Schlitt's Blog:
Randomized Pi calculation
Apr 02, 2007 @ 15:04:00

Since there is no "magic variable" to get a value for Pi in an application, Tobias Schlitt offers up the next best thing - his homegrown solution for creating the value (using a randomized variation).

I don't know which is the most common way to calculate Pi in computer programs, but from the stochastics book a read for my recent stochastics exam, I have a randomized variation, which is quite cool I think.

The code example is included along with a bit of explanation for those not familiar with the concepts behind it. It uses two of PHP functions, pow() and mt_rand(), to run through a series of iterations and, using a preset precision value, find the "hits" to finally calculate the value at the end.

tagged: randomize pi calculation pow mtrand precision randomize pi calculation pow mtrand precision

Link:


Trending Topics: