0% complete

Operators · Lesson 6 of 6

String Operators

Join text with concatenation and interpolate values safely.

Lesson

The dot operator concatenates strings, and .= appends to an existing string. Interpolation inside double quotes is convenient, while braces clarify variable boundaries. Build HTML with escaped values; concatenation itself does not make untrusted text safe. Use a template system for larger HTML output so presentation and escaping remain consistent. Further guidance Evaluate an expression from its grouped parts and add parentheses whenever precedence is not obvious. Check divisors before division, be cautious with floating-point equality, and avoid changing state inside a complicated expression. Small, named intermediate values make calculations easier to verify. Practice task: Create a fresh example for String Operators. Predict the result before running it, then change one input and explain why the result changes. Test a normal case and one boundary or invalid case where it applies. Compare your output with the example and note one rule you would use in a real project.

Code examples

String Operators
PHP
$message = 'PHP';
$message .= ' tutorial';
echo $message;
Expected output
PHP tutorial

Key points

  • Join text with concatenation and interpolate values safely.
  • Make calculation order explicit with parentheses and named intermediate values.
  • Check edge cases such as zero divisors and floating-point precision.

Your learning progress

Finish this lesson

Optional practice

PHP playground

This site does not execute learner-provided PHP code. Connect a secured PHP sandbox service before enabling code execution.

Execution is disabled. No code is sent to a server.