Lab Introduction
Lab: PHP String Building and Processing Basics
Video Runtime: 09:39
In this lab, you and I are going to work with strings. You’ll learn about the why, when, what, and how of string building and processing with PHP. You’ll learn about embedding variables to make a string dynamic, concatenating strings, shorthand versions, formatting strings, counting the length, checking if a string has a substring in it, and more.
To get started, let’s spin up a new test website. I’ll walk you through the process using:
- DesktopServer
- PhpStorm
- UpDevTools
- Kint PHP Debugger plugin
Getting a Kint Error?
If you are getting a d()
or ddd()
function not found fatal error with either Kint PHP Debugger or UpDevTools activated, it’s due to the order in which WordPress loads the plugins.
In order to use d()
and ddd()
functions, these must be loaded into memory. That means Kint needs to be loaded first.
Using UpDevTools
If you are using UpDevTools, you can change it to be a must-use plugin by doing the following steps:
- Create a folder in the
wp-content
folder calledmu-plugins
. - Move UpDevTools to this folder.
- Create an autoloader file and load UpDevTools/bootstrap.php file.
Here is a link to the gist for the must-use autoloader file.
Using Kint PHP Debugger plugin
If you are using the Kint PHP Debugger plugin instead of UpDevTools, make sure that your Sandbox plugin’s folder comes after this plugin. You can name it sandbox
for example.
Using the Debug Toolkit plugin
If you are using the Debug Toolkit plugin instead of UpDevTools, you have a couple of choices:
- Move the plugin to the
wp-content/mu-plugins/
folder to make it a must-use plugin. See instructions here. - Or install it through the WordPress Plugin admin UI and then use the debugger functions after all of the plugins have loaded.
For option 2, that means you can’t use d()
or ddd()
in the root of the plugin. Rather, you’ll want to wrap it inside of a callback that’s registered to an event, such as:
add_action( 'plugins_loaded', function() { // your code in here. ddd( 'it works!' ); } );
And we’ll build a quick little sandbox plugin that you’ll use to “play” in during this lab. Come setup your work environment to start the lab.
-
Want the plugin code? Click here.
Whoever says that coding is hard, just smack them.
Episodes
Total Lab Runtime: 02:50:33
- 1 Lab Introductionfree 09:39
- 2 Embedding Variables in a Stringpro 15:16
- 3 Embedding Complex Variablespro 13:37
- 4 Concatenating Strings with a Dotpro 08:47
- 5 Concatenating and Assigning Shorthandpro 05:58
- 6 Formatting a String using Placeholderspro 15:16
- 7 Specifying Which Argument in a Formatted Stringpro 04:18
- 8 Has Substringpro 21:47
- 9 Replacing Substringspro 13:03
- 10 Get the String's Lengthpro 14:11
- 11 Character Set Encoding - It Matters!pro 11:42
- 12 Has Substring - for UTF-8pro 16:45
- 13 Replacing a UTF-8 Substringpro 05:56
- 14 Stripping out Characters or Entitiespro 10:51
- 15 Wrap it Upfree 03:27