-1

I need help writing a program that outputs the number of characters, words, and lines of the given input.

This is what I have so far. It counts how many characters there are, but not the amount of words and lines.

<?php
if (isset($_POST['Submit1']))
{
    echo "characters: = " . strlen($_POST["name"]);
}

?>

    <form method="POST" action="dummy.php">
    
    text : <input type="text" name="name"></br></br>
    <input type="submit" name="Submit1" value="analyze">
    
    </form>
hurikhan77
  • 5,881
  • 3
  • 32
  • 47
  • 1
    Please add the expected output it will easy to understand. – Kosha Sanghvi Sep 04 '21 at 06:05
  • 2
    [count_​chars](https://www.php.net/manual/en/function.count-chars.php) ... counts chararcters, [str_​word_​count](https://www.php.net/manual/en/function.str-word-count.php) ... counts words. Both relatively easy to find when searching the web for "php count characters" or "php count words". I don't think you can count lines using a `text` input – brombeer Sep 04 '21 at 06:28
  • 2
    Does this answer your question? [Count lines in a posted string](https://stackoverflow.com/questions/7955402/count-lines-in-a-posted-string) – Tsyvarev Sep 05 '21 at 10:33
  • no it doesn't but i did it by myself idk how but it worked – hazem badawi Sep 11 '21 at 19:20

1 Answers1

0
"echo "\lines=". $count = count(explode("\n", $_POST['name']));"

that's how to count lines I don't know why I didn't found any thing on the internet about this it took my like a full week

  • Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-ask). – Community Sep 11 '21 at 20:40