Count the characters of message

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • bb nicole
    New Member
    • Jan 2007
    • 127

    Count the characters of message

    Is it have any php coding can count the character of messages, and after the message's character dint excess 160 character, it is first message, excess 160, it will show that the message is second message and so on, excess 350, it will become third message. is it use if else statement?
    But how to count the characters of message? Thanks.... :)
  • MMcCarthy
    Recognized Expert MVP
    • Aug 2006
    • 14387

    #2
    You have posted this in the Articles section. I am moving it to the PHP forum.

    ADMIN

    Comment

    • code green
      Recognized Expert Top Contributor
      • Mar 2007
      • 1726

      #3
      But how to count the characters of message?
      In what format is the message. A string, a file? The most flexible way to handle strings in this way, is to explode() them into an array. The powerful PHP Array functions can then be used

      Comment

      • adamalton
        New Member
        • Feb 2007
        • 93

        #4
        Are you meaning a text input on a web page that has a counter next to it, so that it shows a count of how many characters are left? If so I think you need to use javascript.

        If you want php to count the characters AFTER the form has been submitted then you could use strlen().

        [PHP] $length_of_mess age = strlen($POST_['message']);
        if($length_of_m essage<150)
        print "Your message is less than 150 characters";
        elseif($length_ of_message<300)
        print "Your message is more than 150 but less than 300";
        else
        print "Your message is really long";[/PHP]

        Comment

        • bb nicole
          New Member
          • Jan 2007
          • 127

          #5
          Originally posted by code green
          In what format is the message. A string, a file? The most flexible way to handle strings in this way, is to explode() them into an array. The powerful PHP Array functions can then be used
          Code:
          while($rows = mysql_fetch_array($result)){
          	$bc_id=$rows['bc_id'];
          	$company_login=$rows['company_login'];
          	$bc_time=$rows['bc_time'];
          	$bc_status=$rows['bc_status'];
          	$bc_total_sent_out=$rows['bc_total_sent_out'];
          
          	$alert_message = $company_login." id=".$bc_id." @".$bc_time." sent=".$bc_total_sent_out." s=".$bc_status;
          	
          	$alert_full_message = $alert_full_message.$alert_message."|";
          
          
          }
          echo "$alert_full_message</br>";
          output:
          nusuara id=1 @2007-05-15 10:18:04 sent=0 s=2|vads id=3 @2007-05-15 10:18:04 sent=0 s=3|nusuara id=4 @2007-05-15 10:18:04 sent=10000 s=3|


          But i want to split the output like:
          nusuara id=1 @2007-05-15 10:18:04 sent=0 s=2
          vads id=3 @2007-05-15 10:18:04 sent=0 s=3
          nusuara id=4 @2007-05-15 10:18:04 sent=10000 s=3
          and so on...

          i'm using explode() as below:
          Code:
          $data = $alert_full_message.$alert_message."|";
          list($alert_full_message, $alert_full_message, $alert_message) = explode("|", $data);
          echo "$alert_full_message</br>"; 
          echo "$alert_message</br>";
          but the output is:
          nusuara id=1 @2007-05-15 10:18:04 sent=0 s=2
          vads id=3 @2007-05-15 10:18:04 sent=0 s=3

          how should i edit the code? Thanks... :)

          Comment

          • code green
            Recognized Expert Top Contributor
            • Mar 2007
            • 1726

            #6
            Your original post asked to count characters so I suggested using arrays. I don't see how this applies to your posted code. In fact i'm not sure what you are trying to do. Are you trying to format the HTML output - such as position line breaks? This is better acheived creating a big string then echoing out the string.

            Comment

            • bb nicole
              New Member
              • Jan 2007
              • 127

              #7
              Originally posted by code green
              Your original post asked to count characters so I suggested using arrays. I don't see how this applies to your posted code. In fact i'm not sure what you are trying to do. Are you trying to format the HTML output - such as position line breaks? This is better acheived creating a big string then echoing out the string.

              Sorry, act i ned to count the character, if excess 156 character, the ouput will from output 1 to output 2 as below
              output 1:
              nusuara id=1 @2007-05-15 10:18:04 sent=0 s=2|vads id=3 @2007-05-15 10:18:04 sent=0 s=3|nusuara id=4 @2007-05-15 10:18:04 sent=10000 s=3|

              output 2:
              nusuara id=1 @2007-05-15 10:18:04 sent=0 s=2
              vads id=3 @2007-05-15 10:18:04 sent=0 s=3
              nusuara id=4 @2007-05-15 10:18:04 sent=10000 s=3
              and so on...

              I trying to use explode() as below to seperate the string:
              Code:
              if(condition){
              $data = $alert_full_message."|";
              list($alert_full_message, $alert_message) = explode("|", $alert_full_message);
              echo "$alert_full_message</br>"; 
              echo "$alert_message</br>"; 
               }
              but the output i get is
              nusuara id=1 @2007-05-15 10:18:04 sent=0 s=2
              vads id=3 @2007-05-15 10:18:04 sent=0 s=3


              and the $alert_full_mes sage and $alert_message is from the code below:

              Code:
              while($rows = mysql_fetch_array($result)){
              	$bc_id=$rows['bc_id'];
              	$company_login=$rows['company_login'];
              	$bc_time=$rows['bc_time'];
              	$bc_status=$rows['bc_status'];
              	$bc_total_sent_out=$rows['bc_total_sent_out'];
              
              	$alert_message = $company_login." id=".$bc_id." @".$bc_time." sent=".$bc_total_sent_out." s=".$bc_status;
              	
              	$alert_full_message = $alert_full_message.$alert_message."|";
              
              
              }
              echo "$alert_full_message</br>";
              echo of $alert_full_mes sage will display the output 1. Thanks.

              Comment

              • bb nicole
                New Member
                • Jan 2007
                • 127

                #8
                i got it, thanks.... :)

                Comment

                Working...