Often we need to build strings incrementally. A good example is with building an output HTML string pattern or even a message. You build part of it, do some processing, and then keep appending to the same string and assigning it back to the variable.
PHP gives you a shortcode operator for this process that turns:
$message = $message . 'Welcome ' . $first_name;
$message .= 'Welcome ' . $first_name;.
Both of these lines of code are processed the same way by the PHP interpreter. First, the strings are concatenated. Then the assignment is made to the variable
If you listen carefully, you can hear the 1s and 0s flowing in your computer.
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