PHP program to count the number of words in a string.




<?php

if(isset($_POST["submit"]))

{

$textbox=$_POST["textbox"];

$c=explode(" ", $textbox);

$count=0;

foreach ($c as $key => $value) {

         $count++;

}

echo "<span style='font-size:20px;color:blue'>total words $count</span>";

}

?>

<html>

<body>

<form method="post">

<br><label>enter text</label><input type="text"name="textbox"><br><br>

<input type="submit"name="submit">

</form>

</body>

</html>


output:-





Post a Comment

If you have any doubts, Please let me know
Thanks!

Previous Post Next Post