Forum Moderators: coopster
<?php
$list="I would like to buy some apples, bannanas, pears, grapes." ;
#check the last occurence and replace the value;
$last=strripos($list,',');
$list_explode=str_split($list);
for ($i = 0; $i<=count($list_explode); $i++){
if ($i == $last){
$list_explode[$i] =' and';
}
}
$sorted = implode($list_explode,'');
echo $sorted;
?>
#echos I would like to buy some apples, bannanas, pears and grapes.
[edited by: VarX at 6:07 am (utc) on Feb. 20, 2009]