473,394 Members | 1,734 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

Count the characters of message

127 100+
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
7 2242
MMcCarthy
14,534 Expert Mod 8TB
You have posted this in the Articles section. I am moving it to the PHP forum.

ADMIN
May 10 '07 #2
code green
1,726 Expert 1GB
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
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
bb nicole
127 100+
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
1,726 Expert 1GB
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
bb nicole
127 100+
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
bb nicole
127 100+
i got it, thanks.... :)
May 16 '07 #8

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

Similar topics

9
by: Jerry | last post by:
In limiting textbox input to 500 characters I would like to include a dynamic count of characters input while the user is typing into a textbox. This would obviously be a client side control,...
10
by: Jon | last post by:
I want to count the number of instances of a certain string(delimiter) in another string. I didn't see a function to do this in the framework (if there is, please point me to it). If not, could...
23
by: Paul Mars | last post by:
I need to limit multiline textbox to 3 lines of text and if there are less then 3 lines when leaving, add empty line holders. How can I do this?? Thanks, paul
68
by: Martin Joergensen | last post by:
Hi, I have some files which has the following content: 0 0 0 0 0 0 0 1 1 1 1 0 0 1 1 1 1 0 0 1 1 1 1 0 0 1 1 1 1 0 0 0 0 0 0 0
3
by: waynejr25 | last post by:
can anyone debug my program and get it to run. #include <fstream> #include <iostream> #include <string> #include <cstdlib> #include <map> using namespace std;
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.