Jump to content

Counting Characters in variable returned.


jimbob33

Recommended Posts

Hi there,

I'm trying to write a php echo file to go with a html form.
I need to count and show the total number of characters returned from the variables entered on the form.

Where do I insert this and do I use count() or strlen() or neither?  This may be simple but I'm new to php and struggling.

Here is my php code so far - not sure if you need the code from my html form aswell.

Thanks in advance.

<html>
<body>

Your favourite book is <?php echo $_GET["book"]; ?>.<br />
Your favourite meal is <?php echo $_GET["meal"]; ?>.


</body>
</html>
Link to comment
Share on other sites

Well how exactly are you retrieving the data from the user?  because GET will only work if you use
method="url" in the form.  I suggest using the post method, then the way to count the string length of the submitted stuff is:
[code]
<?php
$fav_book = $_POST['book'];
$fav_meal = $_POST['meal'];
$book_length = strlen($fav_book);
$meal_length = strlen($fav_meal);
//then echo it
echo("<p>Your favorite book is $fav_book.</p>");
echo("<p>Your favorite meal is $fav_meal.</p>");
//and use the length variables however you want, you didn't really go into detail on that
?>
[/code]

plus, the count function is used to count the number of values in an array, so it wouldn't be of use here.
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.