By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
437,949 Members | 1,855 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 437,949 IT Pros & Developers. It's quick & easy.

Count the characters of message

100+
P: 127
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.... :)
May 10 '07 #1
Share this Question
Share on Google+
7 Replies


MMcCarthy
Expert Mod 10K+
P: 14,534
You have posted this in the Articles section. I am moving it to the PHP forum.

ADMIN
May 10 '07 #2

code green
Expert 100+
P: 1,726
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
May 10 '07 #3

P: 93
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_message = strlen($POST_['message']);
if($length_of_message<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]
May 10 '07 #4

100+
P: 127
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
Expand|Select|Wrap|Line Numbers
  1. while($rows = mysql_fetch_array($result)){
  2.     $bc_id=$rows['bc_id'];
  3.     $company_login=$rows['company_login'];
  4.     $bc_time=$rows['bc_time'];
  5.     $bc_status=$rows['bc_status'];
  6.     $bc_total_sent_out=$rows['bc_total_sent_out'];
  7.  
  8.     $alert_message = $company_login." id=".$bc_id." @".$bc_time." sent=".$bc_total_sent_out." s=".$bc_status;
  9.  
  10.     $alert_full_message = $alert_full_message.$alert_message."|";
  11.  
  12.  
  13. }
  14. 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:
Expand|Select|Wrap|Line Numbers
  1. $data = $alert_full_message.$alert_message."|";
  2. list($alert_full_message, $alert_full_message, $alert_message) = explode("|", $data);
  3. echo "$alert_full_message</br>"; 
  4. 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... :)
May 15 '07 #5

code green
Expert 100+
P: 1,726
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.
May 15 '07 #6

100+
P: 127
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:
Expand|Select|Wrap|Line Numbers
  1. if(condition){
  2. $data = $alert_full_message."|";
  3. list($alert_full_message, $alert_message) = explode("|", $alert_full_message);
  4. echo "$alert_full_message</br>"; 
  5. echo "$alert_message</br>"; 
  6.  }
  7.  
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_message and $alert_message is from the code below:

Expand|Select|Wrap|Line Numbers
  1. while($rows = mysql_fetch_array($result)){
  2.     $bc_id=$rows['bc_id'];
  3.     $company_login=$rows['company_login'];
  4.     $bc_time=$rows['bc_time'];
  5.     $bc_status=$rows['bc_status'];
  6.     $bc_total_sent_out=$rows['bc_total_sent_out'];
  7.  
  8.     $alert_message = $company_login." id=".$bc_id." @".$bc_time." sent=".$bc_total_sent_out." s=".$bc_status;
  9.  
  10.     $alert_full_message = $alert_full_message.$alert_message."|";
  11.  
  12.  
  13. }
  14. echo "$alert_full_message</br>";
  15.  
echo of $alert_full_message will display the output 1. Thanks.
May 16 '07 #7

100+
P: 127
i got it, thanks.... :)
May 16 '07 #8

Post your reply

Sign in to post your reply or Sign up for a free account.