473,748 Members | 7,571 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Count the characters of message

127 New Member
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 2261
MMcCarthy
14,534 Recognized Expert Moderator MVP
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 Recognized Expert Top Contributor
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
adamalton
93 New Member
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]
May 10 '07 #4
bb nicole
127 New Member
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 Recognized Expert Top Contributor
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 New Member
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_mes sage 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_mes sage will display the output 1. Thanks.
May 16 '07 #7
bb nicole
127 New Member
i got it, thanks.... :)
May 16 '07 #8

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

Similar topics

9
10115
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, possibly a custom validator with a function written in javascript. Has anyone done this? Does someone have an example? Regards
10
2861
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 someone let me know if the method I've used below is efficient or if there is a better way to do it, as these will be rather large strings I'm searching in. Thanks Public Shared Function CountDelimiter(ByVal strInput As String, ByVal...
23
2767
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
6826
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
7792
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
8991
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9544
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9372
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9324
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9247
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8243
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6074
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4606
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4874
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

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.