Python Strings, Numbers & Built-in Math Functions
Master PHP text manipulation and numeric computation. Learn the difference between single and double quotes, string length (strlen), substring extraction (substr), replacement (str_replace), and math utilities (round, min, max, rand).
"Single quotes are a camera snapshot of pure text exactly as typed. Double quotes are an interactive display screen that renders variable values right inside the message."
Deep Dive: How It Works
String Concatenation: The dot (.) operator joins strings (e.g. $a . " " . $b).
Variable Interpolation: "User: {$user->name}" evaluates variables inside double quotes.
Core String Functions: strlen(), strpos(), strtoupper(), strtolower(), trim(), and str_replace().
Math Helpers: abs(), round(), ceil(), floor(), min(), max(), and random_int().
Syntax Blueprint
<?php
$greeting = "Hello, {$name}!";
$clean = trim($input);
$rounded = round(3.14159, 2);Interpolate variables inside double quotes and call standard string/math functions.
Core Rules to Remember



Common Beginner Traps & How to Fix Them
Using + to join strings ($msg = "Hello " + "World";).Why it happens: + is strictly an arithmetic operator; it attempts to cast strings to 0 and adds them.
How to fix: Always use . for concatenation ($msg = "Hello " . "World";).
Live Interactive Example
Hit Run Code to see it liveYour Turn: Micro Challenge
No pressure! Edit the starter code below and test your solution with instant feedback.
Format Product Summary
Declare $title = " cloud runner " and $cost = 19.456.
Trim $title and convert it to uppercase.
Round $cost to 2 decimal places.
Print "Product: [TITLE] - $[COST]".
Finished reading and practicing?
Mark this lesson as completed to update your course progress.