From the course: PHP: Design Patterns

Unlock the full course today

Join today to access over 22,600 courses taught by industry experts or purchase this course individually.

The strategy pattern in action

The strategy pattern in action - PHP Tutorial

From the course: PHP: Design Patterns

Start my 1-month free trial

The strategy pattern in action

- The strategy pattern is common to most of the frameworks, especially for repetitive tasks that are slightly different, depending on conditions, which is the point of the strategy pattern itself. In this example, I've used Composer to install Zend Filter and Zend Internationalization Libraries. You can see the results here. Filtering data is challenging and depending on what type of data you're expecting and want, the process is completely different. For example, if you ask a user for a phone number, you know that eventually it'll be all numbers. You might need to filter a few things first, but it will end up being numbers. Alternatively, if you ask a user for an email address you really wanna see the @ sign. In this example, we've started with a simple phrase that includes an ampersand and a single quote. The first filter we use escapes HTML entities. The second strips anything that is not alphanumeric from the string. That includes spaces. And the third and final filter, strips…

Contents