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

php[architect]:
It’s About Time
Jan 07, 2019 @ 18:08:02

On the php[architect] site they've shared an article from their December 2018 edition by Colin DeCarlo and issues with dates and times that most developers deal with at some point in their careers.

As applications scale and gain adoption, dates and time become much more of a concern than they once were. Bugs crop up, and developers start learning the woes of time zones and daylight saving time. Why did that reminder get sent a day early? How could that comment have been made at 5:30 a.m. if the post didn’t get published until 9:00 a.m.? Indiana has how man time zones?!

Luckily, PHP developers have the tools they need to face these problems head-on and take back control of their apps.

The article covers some of the basics of "time" and some of the concepts that PHP uses to measure it. It then introduces the different time functionality that PHP offers including timestamps and functions like strtotime and date as well as the DateTime handling. They dig into this last one in more detail before talking about timezones and date arithmetic.

tagged: article phparchitect magazine date time datetime introduction tutorial

Link: https://www.phparch.com/2018/12/its-about-time/

TutsPlus.com:
How to Use AJAX in PHP and jQuery
Jan 07, 2019 @ 17:40:40

The TutsPlus.com site has a new tutorial posted showing you how you can use PHP, jQuery and AJAX together to help make the overall user experience of your application better and more responsive.

Today, we’re going to explore the concept of AJAX with PHP. The AJAX technique helps you to improve your application's user interface and enhance the overall end user experience.

The post starts with an introduction to AJAX - what it is, how it's commonly used and how the normal requests flow. They then show how it works with normal "vanilla" Javascript (no jQuery) and how that compares to the jQuery version. It then dives into the real-world example script, showing how to create a form that sends login information to the backend for evaluation via a POST request.

tagged: ajax tutorial jquery login form introduction

Link: https://code.tutsplus.com/tutorials/how-to-use-ajax-in-php-and-jquery--cms-32494

Zend Blog:
Modern cryptography in PHP 7.2 with Sodium
Nov 16, 2018 @ 18:14:24

On the Zend blog there's a new tutorial posted by Enrico Zimuel covering the use of libsodium in PHP 7.2 to provide stronger encryption for your data.

Recently, at ZendCon & OpenEnterprise 2018, I presented a session about the usage of Sodium in PHP 7.2. Here you can find the slides of this session.

Sodium is a powerful library for modern cryptography. It is a portable, cross-compilable, installable and packageable fork of NaCl, a famous cryptographic tool designed by Prof. D.J. Bernstein.

The tutorial begins with an outline of the Sodium encryption including the algorithms it can use and how it helps to prevent side-channel attacks. It then lists out some of the common use cases and provides a simple code sample showing how to use it to encrypt a simple message with a randomly generated key.

tagged: cryptography modern libsodium tutorial introduction

Link: https://blog.zend.com/2018/11/06/modern-cryptography-in-php-7-2-with-sodium/#.W-7xpJNKi-o

TutsPlus.com:
Write to Files and Read Files With PHP
Nov 15, 2018 @ 16:41:04

TutsPlus.com has continued their series of posts covering some of the basics of the PHP language with their latest article. In this newest tutorial they cover reading from and writing to files using functionality already included with the language.

In this tutorial, you'll learn several important functions in PHP which are sufficient for all your basic file reading and writing needs. You'll learn how to read a file, write to a file, write to a text file, and check if a file exists.

Luckily, PHP provides a lot of functions to read and write data to files. In this tutorial, I'll show you the easiest ways to read data from a local or remote file and how to use flags to write to files exactly how we want.

The tutorial is broken down into several sections:

  • checking if a file exists
  • reading data from a file
  • writing data to a file
  • reading and writing data to files

Each section comes with a bit of description and code examples showing it in action. The post wraps up with some final thoughts and "gotchas" that you need to know when working with files in PHP (especially large ones).

tagged: tutorial introduction file read write beginner

Link: https://code.tutsplus.com/tutorials/reading-and-writing-data-to-files-in-php--cms-32117

TutsPlus.com:
PHP Integers, Floats, and Number Strings
Nov 12, 2018 @ 18:11:39

On the TutsPlus.com site they've continued their series of posts introducing you to some of the basic functionality included with the PHP language. In this latest tutorial they focus on integers, floats, and number strings and how to determine which you're using.

Working with numbers in PHP seems to be a trivial concept, but it can be quite confusing. It looks easy at first because PHP provides automatic type conversion. For example, you can assign an integer value to a variable, and the type of that variable will be an integer. On the next line, you can assign a string to the same variable, and the type will change to a string. Unfortunately, this automatic conversion can sometimes break your code.

There are a lot of types for numeric values as well. In this tutorial, you'll learn about integers and floats in PHP, as well as the functions which can be used to determine the type of numbers that we are dealing with and convert between them. You'll also learn how to convert integers and floats to and from numerical strings.

The post starts by giving a summary of each of the types - integers and floats - along with the concepts of infinity and NaN. It then covers the use of "numerical strings" in PHP and the automatic type switching that can happen when using them with actual number values. The post wraps up with examples of how to cast values from strings to integers (and back) along with some final thoughts.

tagged: tutorial integer float numberstring number introduction beginnner

Link: https://code.tutsplus.com/tutorials/php-integers-floats-and-number-strings--cms-32048

TutsPlus.com:
How to Use the Symfony Event Dispatcher for PHP
Oct 29, 2018 @ 18:40:03

The TutsPlus.com site has posted another tutorial where they go in-depth with one of the components of the Symfony framework. In this new tutorial they cover the Symfony Event Dispatcher component including its basic use via events and subscribers.

Today, we're going to learn how to use the Symfony event dispatcher component, which allows you to create events and listeners in your PHP applications. Thus, different components of your application can talk to each other with loosely coupled code.

[...] The event dispatcher component provides three elements that you could build your app architecture around: event, listener, and dispatcher. The whole system is orchestrated by the dispatcher class, which raises events at appropriate points in an application and calls listeners associated with those events.

The tutorial starts with the command you'll need to get the dispatcher installed and examples of:

  • creating events
  • dispatching the events to subscribers
  • listening for the events

The tutorial then covers subscribers, reusable listeners that can be added to the list for handling when an event fires. Code examples are included for all topics.

tagged: symfony event dispatcher component tutorial introduction

Link: https://code.tutsplus.com/tutorials/handling-events-in-your-php-applications-using-the-symfony-eventdispatcher-component--cms-31328

Christopher Pitt:
Building a blog - Introduction & Posts
Oct 29, 2018 @ 17:56:15

Christopher Pitt has kicked off a new series of posts to his site covering the creation of a new blog system. It's not just any blogging system, however. In this system he's developing it as an asynchronous application using preprocessing. In the introduction to the project he fills in more of the details:

I’ve been building this blog, for a few days now, and it’s been a fun experience. This is partly because it’s an asynchronous application, and partly because it uses a lot of preprocessing.

I thought it would be interesting for me to describe how it is put together, in an ad-hoc sort of series. In the series, I’ll show bits of code and links to libraries I’ve used. I’ll talk about why I’ve chosen to do things in certain ways, and what I could improve (short of deleting everything and starting over with a mature framework).

In this first part of the series, he includes a "tiny bit of code" showing a component of the system before the preprocessing has been run. He's also posted the second part of the series that continues covering the functionality for handling "posts" in more depth (including the use of flat files for content storage and functionality to output Markdown content as HTML).

tagged: tutorial series part1 part2 blog introduction asynchronous preprocessing

Link: https://assertchris.io/post/2018-10-24-building-something-new

TutsPlus.com:
How to Zip and Unzip Files in PHP
Oct 24, 2018 @ 18:35:56

The TutsPlus.com site has a tutorial posted showing how to make use of the ZIP functionality in PHP to handle the compression and decompression of ZIP archives programatically.

Compressing files when transferring them over the internet has a lot of advantages. In most cases, the combined total size of all the files in the compressed format comes down by a nice margin. This means that you will save some of your bandwidth, and users will also get faster download speeds.

[...] One factor that can discourage you from compressing files or make the process very tiresome is the fact that you might be doing it manually. Luckily, PHP comes with a lot of extensions that deal specifically with file compression and extraction. You can use the functions available in these extensions to automatically compress files in PHP.

This tutorial will teach you how to zip and unzip (compress and extract) files to and from a zip archive in PHP. You will also learn how to delete or rename files in an archive without extracting them first.

The tutorial starts with the compression of files making use of the ZipArchive class to create a new instance, add files to compress and close it out to write the resulting archive. Next it shows the reverse, using the same class to create an instance and extraction path. There's also an example of using a loop for even more control of which files are included in the archive.

tagged: tutorial zip unzip introduction ziparchive archive compress

Link: https://code.tutsplus.com/tutorials/file-compression-and-extraction-in-php--cms-31977

StarTutorial.com:
Modern PHP Developer - Iterator
Oct 16, 2018 @ 17:08:16

StarTutorial has continued their "Modern PHP Developer" series of tutorials with their latest covering the use of Iterators for working with sets of data.

If you have used a for loop in PHP, the idea of iteration is most likely not foreign to you. You pass an array to a for loop, and perform some logic inside the loop, but did you know that you can actually pass data structures other than arrays to a for loop? That's where Iterator comes into play.

The tutorial starts by introducing some of the basic concepts of what iterators are and how they're represented in PHP in their most basic form: arrays. They cover some of the basic array handing and functions before getting into the actual Iterator object handling. The article is then broken up into a few parts covering iterators and their functionality:

  • Your first iterator class
  • Why iterator?
  • SPL Iterators
  • ArrayObject vs SPL ArrayIterator
  • Iterating the File System
  • Peeking ahead with CachingIterator
  • Generator

Code and a summary of the functionality is included in each section providing you with a great start towards using iterators over simple arrays in your modern PHP applications.

tagged: developer tutorial introduction modern iterator

Link: https://www.startutorial.com/articles/view/modern-php-developer-iterator

TutsPlus.com:
Trigonometry, Random Numbers and More With Built-in PHP Math Functions
Oct 16, 2018 @ 16:56:01

The TutsPlus.com site has another great PHP tutorial for those new to the language covering mathematical functionality in the language, from the basics out to more complex topics like trigonometry and random number generation.

Basic maths is used a lot during programming. We need to frequently compare, add, multiply, subtract and divide different values when writing code.

Sometimes, the maths required in a program can be more involved. You might need to work with logarithmic, trigonometric or exponential functions. In this tutorial, I'll discuss how to use each of these functions in PHP, with examples.

This tutorial will introduce you to the built-in math functions in PHP for doing trigonometry, exponentiation, and logarithm calculations. We'll also look at rounding and generating random numbers.

They start off with some of the "heavy hitters" in PHP's math functionality and how how to perform trigonometric operations with the likes of sin, cos and tan. This is applied to create an interesting dynamic image using the GD functionality. Next up comes the exponential and logarithmic functions with simple examples followed by a section sharing some other useful math functions for more everyday needs.

tagged: tutorial math trigonometry random number introduction

Link: https://code.tutsplus.com/tutorials/mathematical-functions-in-php--cms-31972


Trending Topics: