PHP Strings

Manipulation

$s = "Hello Phper";
echo strlen($s);       # => 11
echo substr($s, 0, 3); # => Hel
echo substr($s, 1);    # => ello Phper
echo substr($s, -4, 3);# => hpe
echo strtoupper($s);   # => HELLO PHPER
echo strtolower($s);   # => hello phper
echo strpos($s, "l");      # => 2
var\_dump(strpos($s, "L")); # => false

See: String Functions

Multi-line

$str = "foo";
// Uninterpolated multi-liners
$nowdoc = <<<'END'
Multi line string
$str
END;
// Will do string interpolation
$heredoc = <<<END
Multi line
$str
END;

String

# => '$String'
$sgl\_quotes = '$String';
# => 'This is a $String.'
$dbl\_quotes = "This is a $sgl\_quotes.";
# => a tab character.
$escaped   = "a \t tab character.";
# => a slash and a t: \t
$unescaped = 'a slash and a t: \t';
Comments