PHP script Calculating Total Character

By . Category: PHP Tags: ,

irnanto.comCalculate the number of strings to determine the number of characters in a word or phrase. Calculate the length of the string would be very troublesome if we calculate it manually and if the number of characters that will count very much. To overcome the problem of counting the number of characters, words or long sentences, we must create a system that can count the number of characters from each string to a word, sentence or paragraph.

The system calculates the number of characters that will be built using the PHP programming language. The process of counting the number of characters in the application is very simple: we only use the functions available in PHP to be able to know the number of characters or strings. Application count the number of these characters, I often use to determine the length of the character of a title that I will make in a blog.

form count the number of characters and count the number of words

form count the number of characters and count the number of words

How to Calculate Number of Characters

The process of calculating the amount of this character is to enter a word, sentence, paragraph or text content which we will count the number of characters in a textarea that has been provided, then click calculate for the process of counting the number of characters. PHP script to count the number of characters as below.

<h1>Calculate Number of Characters</h1>
<form id=”form1″ name=”form1″ method=”post” action=”<?php echo $_SERVER[‘PHP_SELF’]; ?>”>
   <textarea name=”karakterq”></textarea><br/><br/>
   <input type=”submit” name=”hitung” id=”hitung” value=”Submit” />
</form>
<?php
   if(isset($_POST[‘hitung’])){
      $hasil=strlen($_POST[‘karakterq’]);
      echo $hasil . ” character”;
   }
?>

You already know if the meaning or intent script above? , I think you already know everything. There are also other scrip as below.

How to Calculate Number of Words

Used almost the same script with script count the number of characters, but there are few parameters that determine the calculation of the amount of this word is to calculate the number of spaces in a sentence or paragraph. Example script count the number of words as below.

<h1>Count the number of words<h1>
<form id=”form2″ name=”form2″ method=”post” action=”<?php echo $_SERVER[‘PHP_SELF’]; ?>”>
   <textarea name=”kata”></textarea><br/><br/>
   <input type=”submit” name=”hitungkata” id=”hitungkata” value=”Submit” />
</form>
<?php
   if(isset($_POST[‘hitungkata’])){
      $hasil=explode(” “, $_POST[‘kata’]);
      echo count($hasil) . ” words”;
   }
?>

Very easy right. Below are examples of sentences in the form of input display count the number of characters and the results of the calculations.

input sentence in the form count the number of characters and count the number of words

input sentence in the form count the number of characters and count the number of words

Results count the number of characters and the result of counting the number of words

Results count the number of characters and the result of counting the number of words

Good luck PHP Script Calculating the Number Character. Read also other interesting articles yaa.

Ads

No comments yet untuk “PHP script Calculating Total Character”

Tinggalkan Komentar