Logo  

CS479/579 - Web Programming II

Displaying ./code/PHP/simple/explode.php

#!/usr/bin/php
<?php
  if ($argc < 2) {
    printf("Usage: ./explode.php <string>\n");
    exit(1);
  }
  $str = $argv[1];
  $str = trim($str);
  echo ">{$str}<\n";
  printf("Length of str = %d\n", strlen($str));
  $arr = explode(":", $str);
  $arr[] = "something";
  var_dump($arr);

  printf("Number of elements in the array arr = %d\n", count($arr));
  list($one,$two,$three,$rest) = $arr;

  printf("One: %s, Two: %s, Three: %s, Rest: %s\n", $one, $two, $three, $rest);
?>