Count characters from an input without spaces between words

Asked

Viewed 67 times

0

$nome = $_POST['nome'];
$data = $_POST['data'];
$quantidade_car  = strlen(trim($nome));
var dump($quantidade_car);

echo "$nome <br> $data <br> $quantidade_car";

<form action="resultado-formulario.php" method="POST">

  <input name="nome" type="text" placeholder="Nome Completo">
  <input name="data" type="date">

  <button type="submit">Enviar</button>

</form>

1 answer

1


Give a replace in the spaces:

$quantidade_car  = strlen(trim(str_replace(" ","",$nome)));

function str_replace php

Edit: counting values per word

    $nome = $_POST['nome'];
    $data = $_POST['data'];

    $palavras = explode(" ", $nome);

    foreach ($palavras as $palavra){
        echo "$palavra <br> $data <br>". strlen(trim($palavra));
    }

    <form action="resultado-formulario.php" method="POST">

      <input name="nome" type="text" placeholder="Nome Completo">
      <input name="data" type="date">

      <button type="submit">Enviar</button>

    </form>
  • 1

    Opa, thanks Alvaro Alves! perfect!

  • If you have met the need, please mark as answer :D

  • Alvaro Alves, I have one more question, can you help me ?

  • @Johnnysilva clear, I’m at your disposal

  • Thank you, your previous answer was great and helped me, but I have another question. This function is displaying the general input parameters, however I would like to separate the word inserted in the input and count the characters per word, I don’t know if you could understand.

  • yes, I understand, a moment that I already edit the answer for you :D

  • @Edited Johnnysilva, if you have met the need, mark it as accepted answer

  • 1

    very good! Thanks again for the help! Orbigado xD

Show 3 more comments

Browser other questions tagged

You are not signed in. Login or sign up in order to post.