There are times when you need to know the length of a string. For example, if you are checking for a string and you want to know if it’s at the end of another string, then you need to know the length of what you are looking for first. That’s a good example.
Let’s get you started learning about string lengths, how it’s processed (character vs. byte count), and character encoding. In this episode, you’ll work with the PHP instruction
strlen. This instruction counts the number of bytes in the string, not the number of characters. For now, don’t worry about that difference. We’ll talk more about bytes versus characters, encoding, and languages in the next episode.
A Word of Caution
Are you building solutions that need to be internationalized? Or is does the language that you are coding need UTF-8 encoding instead of ASCII encoding?
mb_strlen instead, as you can specify the character encoding.
Go watch and do the next episode to see why and when.
Keep It Simple, Stupid (KISS) - the best kiss you'll get in code.
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