Topics PHP Basics Strings & String Operations
beginner 10 min read

Strings & String Operations

String manipulation, concatenation, interpolation, and heredoc syntax.

Strings in PHP

Single vs Double Quotes

$name = "Alice";
echo "Hello \$name"; // interpolates
echo 'Hello $name'; // literal

Concatenation

$greeting = "Hello" . " " . "World";

Heredoc & Nowdoc

$html = <<

Title


HTML;

Common String Functions

strlen()
strpos()
substr()
str_replace()
explode() / implode()
trim()
strtolower() / strtoupper()

Examples

<?php
$text = "  Hello, World!  ";
echo trim($text) . "\n";
echo str_replace("World", "PHP", $text);

Your Notes

Sign in to take notes for this lesson.

Discussion

Sign in to join the discussion.

Flashcards

Sign in to create flashcards.