PHP: Basic String Operations

By Xah Lee. Date: . Last updated: .

Join Strings

Strings can be joined by the period ..

<?php
// use period to join string
echo "Once " . "upon a time";
?>

Length

<?php
$aa = "abc";
echo strlen($aa);
# 3
?>

Substring

substr( $myStr, $startIndex, $length)

String index starts at 0.

<?php
$a = "abcde time";
echo substr($a,0,4);
# abcd
?>

PHP, String