Why is PHP echoing post with string count?

Posted March 7, 2016 2.4k views

For some reason when I use the POST method for a from lets says the value to name is Bob. When it echos the $_POST['name'] is says string(3) “Bob” rather then just printing Bob. Even if I do a var dump it still shows up the same way.

  • Can you share your code here.

  • My code for the form is

    <form method="post" action="savePage.php">
    <input type="text" name="name" value="Test">
    <input type="submit" value="Save">

    The only other code is my doctype and body and stuff like that but nothing in the head.

    Here is the savePage.php

    echo $_POST['name'];

    That’s it because I was having other problems so I tested it doing the simplest thing and my code come out like this:

    string(4) “Test”

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Submit an Answer
1 answer

The post method for the PHP echoing is as below -

   if( $_POST["name"] || $_POST["age"] ) {
      if (preg_match("/[^A-Za-z'-]/",$_POST['name'] )) {
         die ("invalid name and name should be alpha");
      echo "Welcome ". $_POST['name']. "<br />";
      echo "You are ". $_POST['age']. " years old.";


      <form action = "<?php $_PHP_SELF ?>" method = "POST">
         Name: <input type = "text" name = "name" />
         Age: <input type = "text" name = "age" />
         <input type = "submit" />


The output will be Name: Age: Submit (tab)