hello. a part of my code is below. im just wondering if theres a more efficient way of doing this. what it does is take a string and output stars for each word apart from the last three words. so if i input 'How much wood would a wood chuck chuck if a wood chuck could chuck wood' i would get back '** ** could chuck wood'.
<html>
<body>
<?php
if(isset($_POST['sentence']))
{
$sen = $_POST['sentence'];
}
$sen_ar = explode(' ', $sen);
$count = count($sen_ar);
$num = 0;
while($num < $count)
{
if($num == $count - 3 || $num == $count - 2 || $num == $count - 1)
{
echo $sen_ar[$num] . ' ';
}
else
{
echo '***** ';
}
$num++;
}
?>
</body>
</html>
I dont need to create a function out of it as it only runs once and it does work ok. i just think that i might be going about things in a roundabout way when there could be a built in function for something like this.
thanks