Thursday, January 31, 2019

How to Create a Timeline Infographic for Black History Month in Illustrator

20 WordPress Video Plugins and Players to Add Engagement

17 Best WordPress Gallery Plugins

20 Pro (+Cool) Medical Logo Design Ideas for Doctors, Clinics, & More

20 Modern Resume Templates With Clean (Elegant) Designs (2019)

How to Write a Professional PowerPoint Presentation (Discover the Writing Process)

20 Best PowerPoint Presentation Templates—With Great Infographic Slides

New Course: Cinematic Text Animation in Adobe After Effects

How to Make an Event Flyer in Microsoft Word

Wednesday, January 30, 2019

15 Eye-Popping Particle-effect Templates for After Effects (on Envato Elements)

How to Create a Real Estate Newsletter Template in InDesign

How to Create a Wintry Deer Portrait Photo Manipulation in Photoshop

19+ Best WordPress Themes for Consultants & Coaches (2019)

20 Education PowerPoint Templates - For Great School Presentations

20 Awesome Resume Templates (With Beautiful Layout Designs)

New Course: VisBug Quick Start

Creating a Jurassic World Dinosaur Character in Maya: Part 1

Tuesday, January 29, 2019

How to Use Brushes in Adobe Illustrator to Create a Colorful Flamingo

22+ Creative Infographic Resume Templates (Designs for 2019)

How & Why to Add Closed Captions to Social Media Videos

How to Make a Pro Resume on Word With Creative Template Designs

How to Customize Bootstrap’s Sass Files With Grunt

22 Best Hoodie Mockup Templates (Pullover and Zip Up)

How Do I Open and Edit a Template in InDesign?

Try These 3 Practical Projects to Learn WordPress Plugin Development

How to Create a High-Impact Typographic Brochure in Adobe InDesign

15 Best Corporate Slideshow Templates for Adobe Premiere

Wednesday, January 23, 2019

Create a PHP Email Script and Form

Create a PHP Email Script and Form

Forms on websites can be used for a lot of purposes besides being a place to contact the website administrators. In previous posts, I covered how to create a fully functional contact form in PHP and how to build your own Captcha and integrate it in your contact forms. In this tutorial, our focus will be on creating forms in PHP that are meant to serve other purposes like gathering information about a job applicant, booking hotel rooms or getting information about marriage events from clients.

Choosing the Right Fields for your Forms

In the contact form tutorial, we learned that different organizations and websites will most probably want to get specific information from people contacting them in order to assist them in the best possible way. For instance, a contact form on a school website might ask parents information about their kids enrolled in that school. Similarly, the contact form on a shopping website might gather information about the last product people bought in order to serve them better.

If contact forms can vary so much between different websites and organizations, it is reasonable to assume that forms which are supposed to serve completely different purposes have very different fields. For instance, you will most probably ask people booking a hotel room if they will be accompanied by any other adults or children. Asking the same thing of a job applicant would make no sense.

This is an important thing to remember when you follow this tutorial. The basic concept of creating a form, gathering all the information and sending it somewhere ,by email will stay the same but the code will almost certainly need changes to work for your case. You might want to add different input fields to your forms and assign different names to those fields. This will then affect the PHP code in the backend. If you make changes in the forms, make sure you update the PHP code as well.

You can take a look at this list of 20 Best PHP email forms to get some inspiration about the layout of form elements or different input fields that you might want to add to your forms.

  • PHP
    20 Best PHP Email Forms
    Eric Dye

Creating an HTML Form

In this tutorial, we will create a form to book hotel rooms as an example. For simplicity, we will also not use any additional JavaScript or PHP libraries.

With this in mind, lets write the markup of our form. We need to ask people making a reservation their name, email address and phone number. After that, we ask them to provide details about the number of children and adults that will accompany them, the check-in and check-out dates along with the types of room they prefer. In the end we will ask them if there is anything else that we show know before their arrival.

We have used two basic patterns to check if the provided name and phone numbers are valid. Phone numbers follow different formats depending on the locale. This means that you will have to update the value of pattern attribute accordingly.

We have also set the minimum value of adults and children to 1 and 0 respectively. This way we can prevent people from mistakenly adding negative values.

You can add more elements to this form for other services that the hotel provides like pickup, room service etc.

Right now, visitors can set both the check in and check out dates to a past value. We can avoid that by simply setting the value of min attribute on both the check in and check out dates. In our case, we will set the minimum possible check in date to be the current day. The value of min attribute of the check out date will be the check in date.

The JavaScript code below will handle all the logic for us. The months are zero-based so we add 1 to the returned value to get the actual month. The returned date value can be any integer from 1 to 31 depending on the current time.

When the date and month values are in single digits, they are padded with an extra 0 so that the final string stays in a valid format.

The following CodePen demo shows the us how the form behaves after adding the above markup and JavaScript functionality.

Sending the Form Data by Email with PHP

The final step involves collecting all the data from our form and sending it to concerned people in an email. This is actually very easy to do. First we gather all the information using $_POST variables. Once we have the required information we sanitize it to remove anything malicious. Finally, we create the body of our HTML email and then send it using the mail() function in PHP.

The following code will go into a file called reservation.php. The file name will be different if you changed the value of action attribute of the from in previous section.

We begin by sanitizing the name and email address of the visitor. After that we sanitize the check-in date, check-out date, number of adults and number of children using the FILTER_SANITIZE_NUMBER_INT flag. This flag removes all characters from the input except digits and + or - signs. It works out great for sanitizing our dates because we expect them in the format YYYY-MM-DD—just digits and the minus sign. You should go through the PHP documentation to learn about all the sanitization and validation flags.

Once we have sanitized all the input, we start preparing our headers. By including Content-type: text/html in the email headers, we will be able to use HTML tags inside our email. For this tutorial, we are keeping it simple and showing all the user data inside a table. Any special message left by people booking a hotel rooms is shown below the table.

Final Thoughts

In this tutorial, we have covered the basics of creating a PHP email script that sends data from forms filled out by people. When creating forms, it is important to lay the elements out properly and make sure that you only ask for information that is actually required. Creating an unnecessarily long form with improperly laid out elements will discourage users from filling out the form. You should also make sure that every element is named properly. Proper sanitization of user input is important as well.

If you have never created your own forms and are unfamiliar with PHP, it might be better to consider using scripts created by professionals. We have created this list of 20 Best PHP Email forms to help you get started. These form come with extra features like Captcha, scheduling emails and file uploads.

  • PHP
    20 Best PHP Email Forms
    Eric Dye

If you have any questions related to this tutorial, please let me know in the comments.





Navigation Bar Best Practices in WordPress

What Should You Include on Your Personal Resume (CV) Website?

25 Medical PowerPoint Templates: For Amazing Health Presentations

How to Make a Restaurant Menu Template in InDesign

11 Best Microsoft Outlook Add-ins (Email Plugins) For 2019

15 Feature-Packed Bootstrap Admin Templates

How to Make a Rock 3D Text Effect With Photoshop Layer Styles

Monday, January 21, 2019

How to Manage a Web Design Project in Paymo

How to Create a Cool Cut-Out Text Effect in Illustrator

20+ Creative PowerPoint Templates - For Presenting Your Innovative Ideas

How to Quickly Make a Brochure In Microsoft Word Using a Template

Short Course: Better Angular App Architecture With Modules

7 Best Real Estate Video Templates on Placeit for Realtors and Agents (2019)

Introduction to Studio, the Screen Design Tool From InVision

How to Make an Event Flyer for Martin Luther King Jr. Day

Thursday, January 17, 2019

How to Use Animation in Angular 6

3 Top Transition Templates for Adobe Rush

25+ Awesome PowerPoint Templates (With Cool PPT Presentation Designs)

24 Best New Crew Neck Sweatshirt Mockup Templates

Quick Tip: How to Customize Bootstrap 4’s Accordion Component

2 New Web Design eBooks From A Book Apart

The Guitarist's Guide to Being a Tutor: Part 4

The Guitarist's Guide to Being a Tutor: Part 4

In the previous tutorial I looked at the ins-and-outs of being a private tutor. In this tutorial, I  cover obtaining work in schools.

Peripatetic School Tutor

Peripatetic means ‘travelling from place to place, working for short periods of time’. In this example, a peripatetic tutor visits schools typically once or twice per week, rather than being a permanent member of staff.

What to Expect

Viewed positively, a peripatetic tutor has many of the benefits a fully-employed teacher enjoys with few of the drawbacks. For example:

  • Working hours are similar, but rarely as long
  • There’s a fraction of the associated paperwork
  • You can be less qualified
  • You’ll have a higher rate of students who actually enjoy attending

As with anything, it’s not all upside. Some of the difficulties include:

  • Your classroom’s wherever the school puts you—I once had to work out of a supply cupboard
  • Some schools view peripatetic tutors as an annoyance. Consequently, you’ll be the last to know anything, even if it relates to you
  • Some teachers resent your lessons removing students from theirs
  • As a non-permanent teacher, some students, and indeed teachers, won’t respect you 

Bearing all this in mind, here are some opportunities for becoming a peripatetic tutor.

Local Authorities

If a local authority has a department for Music in schools, then it follows they may periodically wish to employ peripatetic tutors.

Authorities advertise when they need tutors, or have a single hiring period (typically in August, ahead of the forthcoming new school year in September). Check their website for such details, which’ll at least give you a point of contact for enquiries. Some authorities also advertise in the job section of local papers or websites.

Whilst each authority has its own hiring procedures, some may include the following:

  • They’ll ask for your curriculum vitae, and even a demonstration of your abilities, be it via a supplied recording, or web-links to online content, such as YouTube videos
  • You may be required to attend an interview. As well as being asked a number of questions—your background, your experience and so on. You may have to demonstrate your ability to play and/or teach
  • You may be subjected to some form of background check. In the UK this is known as a DBS check, and is covered in a previous tutorial
  • If successful, you may have to attend a training course. As well as advice on teaching in schools, it’ll cover current legislation on child safety, responsibilities as a tutor and so on
  • There may be a probation period, assessing your performance. This can be the authority supplying your schools with a questionnaire or perhaps a more senior tutor sitting in on some of your lessons and submitting a report accordingly

Formalities

Whilst there’s less paperwork than a permanent teacher deals with, there’ll still be forms the local authority expects in terms of where you’re teaching, the hours you’re teaching, and so on. As well as determining what you’re earning, this is accountability in the event of a school querying anything. 

None of this is fun, but it’s part of the job.

On the plus side, as a formal employee you get paid on a monthly basis, directly to your bank account and tax is deducted at source, so that’s another aspect already dealt with. Some authorities even offer a fuel subsidy. Furthermore, if you’re ill, the authority will arrange cover for you.

Private Schools

This refers to any academic bodies not covered by a local government authority. Examples of this in the UK include Preparatory Schools and Academies.

In seeking work, keep your eyes open for advertising in local papers and their websites.

Some private schools place ads on teaching websites, so use the search phrase ‘private school work’ to yield results. Don’t forget to include your area in the search phrase. 

Failing that, look at the websites of private schools. Firstly, check they have a music department - amazingly, some don’t - and nothing stops you from forwarding your details to them.

Easily Difficult

Dealing with private schools can be a little curious when compared to local authority schools, in that arrangements tend to be less formal, but simultaneously more involved. Where you’ll have fewer direct dealings with a local authority school, and indeed, parents of students, you’ll have far more when working within private schools.

For example, local authority schools often arrange your timetable, whereas some private schools expect you to do it. In terms of payment, instead of guaranteed monthly income, some schools leave such matters to be arranged between you and the parents of your students, whom you’ll be invoicing individually. You may have to invoice the school, and it’s for you to negotiate as to when you get paid, whether it’s weekly, monthly, or even per half-term.

Talking of money, arrangements with private schools can be more lucrative than those of local authorities. However, they’re far less guaranteed. You’ll always encounter a parent who’s slow to settle an invoice, and this is even true of schools on occasion. 

As a peripatetic tutor, if you’re dealing with a school that manages its own budget, you’re way down their list of priorities, so if they wish to hold off payment until they can afford it, they will.

As a side note, include on your invoice a penalty amount if the invoice isn’t settled within a given period of, for example, seven days. You should state that receipt of the invoice constitutes acceptance of your terms. I’ve never had to resort to applying a penalty, but sometimes the threat of it has been enough.

Finally, privately-earned income has not been taxed at source, so be aware of your tax liabilities, as it’s likely you’ll need to declare said income at some point.

Conclusion

Obtaining work in schools is like applying for any job, so:

  • Search for school jobs online
  • Apply to local authorities for peripatetic positions
  • Expect to deal with a lot of paperwork and legislation
  • Apply to private schools
  • Decide whether you want lower regular income in local authority schools, or higher but irregular income in private schools

In the next tutorial I’ll look at how lessons in schools can differ from private tuition, as well as further tutoring opportunities.


15 Best Instagram Story Templates on Placeit for 2019

How to Make a Boxing Event Flyer Template in InDesign

Wednesday, January 16, 2019

15 Top Slideshow Video Templates for Final Cut Pro

How to Make a Photoshop Action to Create a Photo Art Effect

11 Creative Resume Design/CV Tips (With Template Examples for 2019)

14 Simple Invoice Templates: Made For Microsoft Word

How to Make a Watercolor Brush in Adobe Illustrator

Quick Tip: How to Use Adobe Illustrator Files in Figma

How to Use the WowBook jQuery Flipbook Plugin

12 Best Apple Motion Opener Templates

How to Make a Banner for a YouTube Channel (With a Banner Maker)

Tuesday, January 15, 2019

10 Creative Resume Ideas to Stand Out Online in 2019

Two Ways to Create a Frosted Glass Effect in CSS

Hiring (Now) Writers With Copywriting + Design Skills at Tuts+ (Apply Today!)

15+ Annual Report Templates - With Awesome InDesign Layouts

Choosing an eCommerce Platform: Shopify vs. WooCommerce

Choosing an eCommerce Platform: Shopify vs. WooCommerce

Creating an eCommerce store, but not sure what platform is best for you?

With so many products and solutions out there, prospects can be overwhelming. It’s tough to pick which would work best for your venture. Varying costs, system extendability, and ease of use can play huge roles in your choices. For many, however, it comes down to a choice between the two leaders: Shopify or WooCommerce.

There are quite a few other platforms out there, but few of them match the pricing and general usability of these two. That’s why WooCommerce boasts nearly 3 million installs, and Shopify powers more than 700,000 online shops.

Let’s take a look at Shopify and WooCommerce to figure out which best suits your needs.

What Do You Need From Your eCommerce Platform?

Before we put these two eCommerce giants head to head, let's talk about how to choose an eCommerce platform. By knowing what you’re selling, how you’re selling, and how you’ll expand in the future, you’ll be able to choose the platform that’s best for you.

What should you be looking for? Here are some questions to help create your list of needs:

  • How many products are you looking to sell, now and in the future? Is it dozens, hundreds, or thousands?
  • Are you tech savvy? Do you want to handle purchasing your own hosting and domain, and installing software yourself?
  • What forms of marketing are you aiming to use? SEO, pay-per-click advertising, and email marketing are just a few options available out there.
  • Who will be managing the site? Will it be run by one person? Several? Or are you looking to automate as much of the process as possible?
  • If you had the choice, would you prefer ease of use or finer control?
  • Finally, what’s your price range? Do you prefer paying more up front, or is an ongoing payment structure more suitable for what you have in mind?

Once you have some rough answers to these questions, it’s time to compare Shopify and WooCommerce to your list and see how they stack up.

What Does WooCommerce Offer?

With your list of needs in hand, let’s take a look at our first platform: WooCommerce. One of the most commonly used eCommerce solutions on the web (if not the most common), it’s typically one of the first names that you’ll come across when building an online store.

Products for open-source platforms and popular CMSs, like WordPress for instance, sometimes fall into the trap of becoming too generic for many purposes. Let’s see what that means for WooCommerce.

Low Initial Cost

WooCommerce is an eCommerce system built on top of WordPress. Because of this, it’s possible to get a basic site up on your own using only WordPress, WooCommerce, and a free website theme. Aside from hosting and a domain, there’s no cost associated with getting a minimal working online store up and running.

In addition, WordPress developers are also readily available, making it one of the most widely supported CMSs out there.

Free and Paid Add-Ons for Expansion

If WooCommerce doesn’t do what you need right out of the box, it’s likely that there’s a free or paid solution available. If you’re trying to spruce up your site, ThemeForest currently has over 1,000 premium themes for WooCommerce that can be easily installed. If you need something extra that falls on the side of functionality, CodeCanyon has over 1,500 plugins for WooCommerce available.

This is on top of WordPress’s already sizeable collection of plugins that cover almost every feature you could want for an eCommerce site.

Customizable and Developer-Friendly

Need something for your site that you can’t seem to find or apply? WordPress and WooCommerce are known for their developer friendliness. There are a plethora of great developers for the CMS that are ready and willing to help you out. You probably even have one near you!

This ability to customize and extend means that you can adjust your site to do exactly what you want, even if you’re only looking to slowly upgrade over time.

Hands-On

One of the downsides to using WooCommerce for your shop is that if you decide to go it alone, it can be an uphill battle. There is plenty of support available, but sometimes you need to know a little first to keep everything moving. While other eCommerce systems have been simplified to make them easier for beginners, WooCommerce and WordPress try to have finer control for developers.

However, you can set up an entire set on your own without ever working with a developer, if you’re willing to figure out how each piece works on your own. Luckily, there are plenty of guides out there for the platform that can help you get up and running.

Scaling Difficulty

WooCommerce excels at listing dozens or hundreds of products, and even does well with product ranges in the thousands. As you exceed these numbers, however, it becomes difficult to continue scaling without additional assistance.

This typically requires better-performing servers from web hosts, the use of Content Delivery Networks, and working with a professional developer to optimize your site. While this is par for the course with most eCommerce platforms, there are a few out there that have scalability built into their pricing model: like Shopify.

What Can I Expect From Shopify?

Let’s take a look at Shopify next.

Shopify is built explicitly for online stores as opposed to being an extension for a general-use website, like WooCommerce. This creates some trade-offs: typically making it more difficult to add extra eCommerce-adjacent functionality, but easier when it comes to managing a store.

Here are some of the highlights of working with Shopify.

Subscription Pricing Model

With WooCommerce, it’s possible to get a site up for almost no cost. If you wanted your site to be custom instead of built on a free theme, you might have a one-time cost with occasional maintenance as needed—but Shopify uses a different model entirely.

The crux of the Shopify pricing model is a monthly subscription ranging from $29 to $299/month. With that ongoing cost comes a number of benefits, however. These range from discounts on shipping and regular updates to the inclusion of Shopify’s own Content Delivery Network and in-store POS solution.

Easily Scalable

Since you don’t need to manage your own hosting with Shopify, it’s possible to increase the number of products in your store as necessary, without running into limitations. If you experience a massive amount of traffic or need to add more staff to the management area of your store, you can simply upgrade your account, and Shopify handles it for you.

This means that you can spend more time on your business, and you don't need to worry about the technical infrastructure underneath.

Fewer Resources Available

There are significantly fewer resources out there for Shopify than WooCommerce. But that isn’t to say there aren’t any at all—on the contrary, guides, themes, and apps are available for almost any need. But the diversity is slimmer overall.

With a smaller user base and a more niche product than the WooCommerce and WordPress combo, there is a slight lack of variety. While there are thousands (if not tens of thousands) of WordPress themes out there, Shopify has roughly a tenth of that.

The same goes for apps (the Shopify version of plugins). Using SEO services as an example, when working with WooCommerce and WordPress, you may have a few dozen SEO plugins available. With Shopify, there are only a few to choose from.

Final Summary: WooCommerce vs. Shopify

When it comes to deciding between Shopify and WooCommerce, the answer lies in that needs list that we put together back at the beginning. Which platform checked off the most needs?

If you’re looking to experiment, have in-depth control, or have a small budget, then WooCommerce is likely the way to go.

If you’re looking for ease of use, reliable scaling, or tying an eCommerce shop to a brick and mortar store, Shopify might be a better pick for you.

Unfortunately, there isn’t a clear-cut choice, so finding out what your business needs are first is the best way to determine which to go with.

Which eCommerce Platform Do You Use?

WooCommerce and Shopify are two of the most popular online store platforms, but there are many more! What platform do you use, and why do you like it? Let us know in the comments below!


Silly and Hilarious: The Best Royalty-Free Music Tracks for Comedy Movies

22 Best New Brochure Templates for 2019 (Design Inspiration & Ideas)

How to Make a Bi-Fold Brochure in InDesign

New Course: Get Started With Hapi.js

Monday, January 14, 2019

What Is Stock Footage and When Might You Use It?

Quform Vs FormCraft: Top WordPress Form Builder Plugins Compared

50 After Effects Video Templates to Watch on Envato Market in 2019

15+ After Effects Video Intro Templates: For Your Startup Business

How to Create a Stylish, Glowing Outline Text Effect in Photoshop

How to Prototype and Share Your First Mobile App With Adobe XD

20 Top Visual Resume Templates for Artists & Creatives for 2019

How to Make a Mockup in 5 Easy Steps

Thursday, January 10, 2019

What Are Photoshop Actions and How to Install Photoshop Actions

Standard & International Brochure Formats and Dimensions

New Course: Going Beyond the Basics With InVision Studio

25 Best Pitch Deck Templates: For Business Plan PowerPoint Presentations

How to Use the Modulo Operator in PHP

How to Use the Modulo Operator in PHP

PHP has a total of eight arithmetic operators. The most common are addition (+), subtraction (-), multiplication (*) and division (/). A slightly lesser-known, though still very important operator is modulo (%). In this tutorial, we'll focus on the modulo operator. We will discuss what it does and some of its practical uses.

What Does the Modulo Operator Do?

If you have two variables $a and $b, calculating $a % $b—usually pronounced "a modulo b" or "a mod b"—will give you the remainder after dividing $a by $b. Modulo is an integer operator, so  it converts both the operands to integers before calculating the remainder. So basically modulo does integer division and then gives back whatever is left from the dividend.

The sign of the value returned by a modulo operation is determined by the sign of the dividend. In division, the result after dividing two negative numbers will be a positive number. However, that's not the case with the modulo operator. The sign of divisor has no effect on the final value.

Here are a couple of examples:

Floating Point Modulo

If you want to calculate the remainder when two floating point numbers are divided by each other, you will have to use the fmod($dividend, $divisor) function. It returns the floating point remainder after the division. The remainder value will have the same sign as the dividend and its magnitude will be less than the divisor. The three numbers are related by following relation:

Here, the value i will always be an integer.

You should remember that floating point arithmetic is not always accurate due to limitations of the binary or decimal representation of fractions. For example, 1/3 cannot be accurately represented in decimal form. You can keep writing 0.33333.... but at some point you would have to stop. You will get closer to the original value with each additional 3 in the decimal representation but the value will still not be exactly 1/3.

This kind of inaccuracy causes problems with the fmod() function: the results are not entirely reliable.

Here are some examples of the fmod() function:

The second value isn't accurate because 0.2 divides 18.8 perfectly. This is just a shortcoming of calculations in the floating point format used by computers.

Uses of the Modulo Operator

In this tutorial, we will restrict ourselves to integer modulo because it is much more common and has a lot of applications.

Checking if a Number is Multiple of Some Other Number

The result of the modulo operator is zero if the first number is perfectly divisible by the second number. This could be used to check if one number is multiple of the other in a given number pair. Probably the most common use of this property of the modulo operator is in checking if a number is even or odd. Here is an example:

In the above example, you could be getting the list of colors from some user and ask them to only provide even number of colors.

The example below uses a similar reasoning to create groups with 5 students each. In real life, you will have to use extra code to group the students but the basic idea of checking if the total students are multiples of 5 does not change.

Changing Numbers to be Multiple of Some Other Number

In the above section, we used the modulo operator to inform users to only provide input values in certain multiple. If that is not possible, we can also force the input to be even as well as a multiple of 5 or some other number.

The modulo operator provides the whole number left after dividing the first number with the second number. This means that subtracting the remainder from the first number will make it a multiple of the second number. For example, 28 can be changed to be multiple of 5 by taking the modulo 28 % 5. In this case, the modulo will be 3. We can now subtract 3 from the original number to make it a multiple of 5. The following line will force any positive number x to be a multiple of some other positive number y by subtracting an appropriate value from it.

In our previous example with 28 students, we could just leave 3 students out and group other students together.

Put a Limit on the Input

As I mentioned in the beginning of the post, in case of positive numbers the modulo operator will return a number between 0 and N - 1, where N is the divisor. This means that you can put a cap on any input and do some operations repetitively and sequentially. Here is an example:

In the above example, we have just five colors but a total of 180 images. This means that we will have to keep looping through the same five colors and assign them to all our images. The modulo operator fits this need perfectly. It will restrict the value of $i % $color_count between 0 and (5 - 1) or 4 inclusive. In other words, we will be able to pick all colors of our array sequentially very easily.

Do Some Task Every Nth Time in a Loop

When traversing a loop, we can check the value of a variable incremented with each pass through the loop and do some specific task after every nth iteration. One practical use case that comes to mind is updating users about some long-running process. Lets say you are making changes to 1000 different images using PHP. If the changes are significant, this process will take a while to update all images.

In such cases, the users will have no way of knowing if the program is just stuck or actually making any progress. What you could do is report the progress to users after editing every 10th image.

The update_images() function in the above example is completely made up but you could replace it with some other processes like resizing the images, adding watermark, turning them gray scale etc. (Check out my PHP GD image editing tutorials if you want to learn how to programatically edit images in PHP yourself.)

Converting Between Different Units of Measurement

The modulo operator can also be used to convert between different units of measurement. For example, you could use it to change a time duration expressed in number of seconds into the same duration expressed in hours, minutes and seconds. Similarly, you could also convert a large of centimeters into kilometers, meters and centimeters. Here is an example:

We begin by simply dividing the total number of seconds by 3600 and casting the value into an integer. This gives us the total number of hours since every hour has 3600 seconds. In the next step, we subtract 3600 * $hours from the original number of seconds. This gets rid of all the seconds that we have converted to hours. Dividing by 60 now will give us the total number of minutes. Finally, we use the modulo operator to get the number of seconds.

Final Thoughts

As you saw in this tutorial, the modulo operator, though easy to use, has a lot of applications. We began this tutorial by looking at the modulo of both positive and negative numbers as well as floats. After that we covered some common scenarios where we would use modulo. 

If you have any questions related to this tutorial, please let me know in the comments. Do you have any other uses of modulo in mind? Please share them with fellow readers by posting them below.


Eight Ways to Reduce Your Android App APK Size

How to Make a Banner With an Online Banner Maker

10 Essential Tips & Tools All Adobe Illustrator Beginners Should Learn

Wednesday, January 9, 2019

How to Create a PDF Viewer in JavaScript

Why You Should Use Slider Revolution For Your WordPress Site

How to Create Custom Photoshop Actions for Your Photographs

How to Create a Lady and the Tramp Photo Manipulation in Adobe Photoshop

Preview Our New Course on Angular Material

25+ Professional MS Word Resume Templates With Simple Designs For 2019

Quick Tip: How to Implement Dark Mode in Your Website Using Media Queries

How to Make Social Media Icons in Vector

Wednesday, January 2, 2019

Use a Pattern Rope Brush to Create a Rope Text Effect in Illustrator

How to Photograph Landscapes in Winter Light

How to Install, Configure and Secure Your Own Website Server From Scratch

20 Simple Resume Templates (Easy to Customize & Edit Quickly)

How to Make a Portfolio Brochure Template in InDesign

How to Make a T-shirt Video Mockup With Placeit

20 Happy and Upbeat Royalty-Free Music Tracks

38 Stylish Flyer Templates (PSD Flyer Templates)