Jump to content

How to display the word from string(non repeatitive)


gech02ab

Recommended Posts

<?php
$string = "this time, I eat this";
$string = preg_replace("/[^a-z1-0 ]/i",'',$string);
$a = explode(' ',$string);
$words = array();
while ($word = each($a)) {
if (!array_key_exists($word,$words)) $words[$word] = 1;
else $words[$word]++;
}
foreach ($words as $word => $count) {
echo "$word appears $count time".(($count > 1)? 's':'')."\n<br>\n";
}
?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.