'; // Using the concatenation assignment operator (.=) $string1 = 'Hello'; $string2 = 'World'; $string1 .= ' ' . $string2; echo $string1; echo '

'; // Using double quotes (") to directly concatenate variables within a string $string1 = 'Hello'; $string2 = 'World'; $concatenation = "$string1 $string2"; echo $concatenation; echo '

'; /* Newlines */ // Using the "\n" escape sequence echo "Line 1\nLine 2\nLine 3"; echo '

'; // Using double quotes (") echo "Line 1 Line 2 Line 3"; echo '

'; // Using PHP_EOL constant, which represents the correct end-of-line character echo "Line 1" . PHP_EOL . "Line 2" . PHP_EOL . "Line 3"; echo '

'; // Using the nl2br() function to insert HTML line breaks (\n) before all newlines in a string $text = "Line 1\nLine 2\nLine 3"; echo nl2br($text); echo '

'; /* Handling HTML String Input */ // htmlspecialchars() $string = "Test & 'Example'"; $safe_string = htmlspecialchars($string, ENT_QUOTES, 'UTF-8'); echo $safe_string; echo '

'; // htmlentities() $string = "Test & 'Example'"; $safe_string = htmlentities($string, ENT_QUOTES, 'UTF-8'); echo $safe_string; echo '

'; /* Encoding and Decoding */ // Encode $url = urlencode("https://fanshawec.ca?programs=iwd&cpa"); echo $url; echo '

'; // Decode $url = urldecode("https%3A%2F%2Ffanshawec.ca%3Fprograms%3Diwd%26cpa"); echo $url; echo '

'; /* Adjusting strings */ // substr() $string = "You are a wizard, Harry."; $substr = substr($string, 9, 6); echo $substr; echo '

'; // strtok() $string = "Luke, I am your father."; $substr = strtok($string, ","); echo $substr; echo '

'; // strlen() $string = "May the odds be ever in your favour."; $length = strlen($string); echo $length; echo '

'; // Uppercase / Lowercase $string = "hello world"; echo ucfirst($string); echo '

'; echo ucwords($string); echo '

'; echo strtoupper($string); echo '

'; echo strtolower('HELLO WORLD'); echo '

'; /* Replacing Strings */ // str_replace() $search = 'world'; $replace = 'everyone'; $subject = 'Hello world!'; echo str_replace($search, $replace, $subject); echo '

'; // str_ireplace() $search = 'WORLD'; $replace = 'everyone'; $subject = 'Hello world!'; echo str_ireplace($search, $replace, $subject); echo '

'; // trim() $string = " hello world "; echo trim($string); echo '

'; // rtrim() $string = "hello world!!!"; echo rtrim($string, '!'); echo '

'; $string = " hello world"; echo ltrim($string); echo '

';