<?php
error_reporting(E_ALL);
$text = 'some text to do something with, and some more text';
// empty array of words
$words = array();
// split the text the spaces
$hash = explode(' ',$text);
// loop the array
foreach($hash as $word){
// get rind of spaces (incase there was three spaces
$w = trim($word);
// check if the $w is in the array
if(array_key_exists($w,$words)){
$words[$w]++; //increment the count
}else{
$words[$w] = 1;
}
}
foreach($words as $word => $count){
echo "$word = $count<br>";
}