Using the string functions

PHP Manual string functions site: http://www.php.net/manual/en/ref.strings.php

Functions for working with string length and substrings

empty($str)
strlen($str)
substr($str, $i[, $len])

Code that determines if a string is empty

<?php
  if (empty($first_name)) {
    $message = 'You must enter the first name.';
  }
?>

Code that gets the length of a string and two substrings

<?php
  $name = 'Ray Harris';
  $length = strlen($name);            // $length is 10
  $first_name = substr($name, 0, 3);  // $first_name is 'Ray'
  $last_name = substr($name, 4);      // $last_name is 'Harris'
  $last_name = substr($name, -6);     // $last_name is 'Harris'
?>

Back