PHP: Basic String Operations

By Xah Lee. Date:

Strings can be joined by the period “.” symbol.

<?php
$a = "this" . " that";
echo $a; // prints “this that”

Substring extraction is done using the function “substr”. The form is: “substr( $myStr, $startIndex, $length)”. String index starts with 0.

<?php
$a = "once upon a time";
echo substr($a,0,4); // prints “once”

Length of the string is “strlen()”.

<?php
$a = "once";
echo strlen($a); // prints 3

If you have a question, put $5 at patreon and message me.

  1. PHP Install
  2. PHP Basics
  3. String Syntax
  4. String Operations
  5. Array
  6. Hash Table
  7. Looping Thru Array
  8. Function
  9. Write Package
  10. Send HTML Mail
  11. Send Mail with Attachment
  12. MySQL Database Query