[ create a new paste ] login | about

Link: http://codepad.org/chK5mNre    [ raw code | output | fork | 2 comments ]

leethelobster - PHP, pasted on Oct 27:
<?php 

$str = "The lazy dog jumped over the fox";
$spaceCount = substr_count($str, " ");
$letterIndx = 0;

// count number of spaces and then loop
for($i=0; $i<=$spaceCount; $i++) {

  // get space positions
  $spaceIndx = strpos($str, " ", $letterIndx);
  
  // assign word by specifying start position and length
  if ($spaceIndx == 0) {
    $word = substr($str, $letterIndx);
  } else {
    $word = substr($str, $letterIndx, $spaceIndx - $letterIndx);
  }
  
  // push word into array
  $myArray[] = $word;
  
  // get first letter after space
  $letterIndx = $spaceIndx + 1;
}


// reverse the array
$reverse = array_reverse($myArray);

// echo it out
foreach($reverse as $rev) {
  echo $rev." ";
}

?>


Output:
1
fox the over jumped dog lazy The 


Create a new paste based on this one


Comments:
posted by kavi on Jun 27
fsdfsd
reply
posted by kavi on Jun 27
helloworld
reply