473,801 Members | 2,309 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

adding to a string

hi all,

I have a string $string

I initialize the string:
$string = "test string<br>";

I want to add text to the string along my script but:
$string += "more information<br> ";

doesn't seem to work.

Someone an help me?

regards
Stijn
Jul 17 '05 #1
6 49251
El Dijous 29 Gener 2004 16:49, Stijn Goris va escriure:

Hi!
I want to add text to the string along my script but:
$string += "more information<br> ";

doesn't seem to work.


Try:
$string .= "more information<br> ";

Regards

--

En cap cap cap el que cap en aquet cap.
Jul 17 '05 #2
zapf wrote:
$string += "more information<br> ";

doesn't seem to work.

Try:
$string .= "more information<br> ";


Yeah, but why didn't they overload the + operator like other languages?
Because for concatenation, we have ., which is traditionally used for
object access. For that, we have the C++ object pointer operator, ->.
Not that I'm complaining, but it seems to be an unnecessary deviation
from the norm in such a fundamental area.

Jul 17 '05 #3
With total disregard for any kind of safety measures Keith Bowes
<do****@spam.me > leapt forth and uttered:
zapf wrote:
$string += "more information<br> ";

doesn't seem to work.

Try:
$string .= "more information<br> ";


Yeah, but why didn't they overload the + operator like other
languages?
Because for concatenation, we have ., which is traditionally
used for
object access. For that, we have the C++ object pointer
operator, ->. Not that I'm complaining, but it seems to be an
unnecessary deviation from the norm in such a fundamental area.


Becuase thats the way PHP works. The . operator for concatenation
was borrowed from Perl, as was the -> operator (although it
originated in C++)

In PHP += Is used in numeric calculations, I think $i += 2 is the
same as $i = $i + 2.

--
Phil Roberts | Nobody In Particular | http://www.flatnet.net/
Jul 17 '05 #4
Keith Bowes wrote:
Yeah, but why didn't they overload the + operator like other languages?
Because for concatenation, we have ., which is traditionally used for
object access. For that, we have the C++ object pointer operator, ->.
Not that I'm complaining, but it seems to be an unnecessary deviation
from the norm in such a fundamental area.


so that you can do:

<?php
$n = 3;
$s = '6';

echo $n + $s; // 9
echo $n . $s; // 36
echo $s + $n; // 9
echo $s . $n; // 63
?>
compare with my feeble attempt at C++

#include <iostream.h>

int main(void) {
int n=3;
char* s="6";
// I don't know how to display 9 or 36
// as the result of an operation over n
// and s now
cout << n << s << "\n"; // ok for 36 :-)
return 0;
}
--
--= my mail box only accepts =--
--= Content-Type: text/plain =--
--= Size below 10001 bytes =--
Jul 17 '05 #5
it also helps if you are looking at some code that was written a while back,
and you are midstream and see:

$var .= $var2;

you know this is string concatenation not a math addition.

if you were to see:

$var += $var2

you would have no idea if it is $var = $var + $var2 or if it is $var =
"$var$var2"
this is another reason it is serperate.

just my $.02

--
Mike Bradley
http://www.gzentools.com -- free online php tools
"Keith Bowes" <do****@spam.me > wrote in message
news:nx******** ***********@fe0 2.usenetserver. com...
zapf wrote:
$string += "more information<br> ";

doesn't seem to work.

Try:
$string .= "more information<br> ";


Yeah, but why didn't they overload the + operator like other languages?
Because for concatenation, we have ., which is traditionally used for
object access. For that, we have the C++ object pointer operator, ->.
Not that I'm complaining, but it seems to be an unnecessary deviation
from the norm in such a fundamental area.

Jul 17 '05 #6
On Thu, 29 Jan 2004 12:35:45 -0500, Keith Bowes <do****@spam.me > wrote:
$string += "more information<br> ";

doesn't seem to work.


Try:
$string .= "more information<br> ";


Yeah, but why didn't they overload the + operator like other languages?


It's a matter of opinion as to whether this:

<pre>
<?php
print "1" + "2";
print "\n";
print "1" . "2";
?>
</pre>

Should output:

3
12

(which it does)

Or:

12
12

Both are reasonable from different points of view; PHP went with the first.
Given that numeric values often come in as strings from $_GET/$_POST, always
doing arithmetic for '+', and having concatenation as a separate operator
probably makes more sense in the majority of cases.

--
Andy Hassall <an**@andyh.co. uk> / Space: disk usage analysis tool
<http://www.andyh.co.uk > / <http://www.andyhsoftwa re.co.uk/space>
Jul 17 '05 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

10
2693
by: sp0 | last post by:
Is there a reason why to make mix numbers improper when adding? It seems when subtracting and adding, adding a subtracting the whole numbers and fraction parts should be sufficient? what'ch think
23
4760
by: YinTat | last post by:
Hi, I learned C++ recently and I made a string class. A code example is this: class CString { public: inline CString(const char *rhs) { m_size = strlen(rhs);
2
12888
by: John Tyce | last post by:
When a button is clicked, a date is inserted or added into a combo box like this : ComboBox.Items.Add(string) or ComboBox.Items.Insert(0,string); Either way, the new string does not show up in the ComboBox. I get no errors or problems, it just will not work. At load time I am retrieving dates from an Oracle database and adding them to the ComboBox with out any problems. However, once the application is up and running I cannot add to the...
3
4889
by: Jim Heavey | last post by:
Trying to figure out the technique which should be used to add rows to a datagrid. I am thinking that I would want an "Add" button on the footer, but I am not quite sure how to do that. Is that the best method? Do you have a sample of how to do this?
14
18758
by: Paul_Madden via DotNetMonster.com | last post by:
Basically I have a listbox to which I add simple STRING items- I have a progress bar which I increment whenever I populate another portion of the complete set of items I wish to add. What I observe is that as more and more are added, population of the list box takes longer and longer. ie the first 10th of the item set are added much much quicker than the last 10th. THis occurs with about 40,000 listbox items. My worry is the listbox may...
8
3107
by: gthorpe | last post by:
Hi, I have a question about string constants. I compile the following program: #include <stdio.h> #include <string.h> int main(void) { char str1 = "\007";
34
2669
by: Larry Hastings | last post by:
This is such a long posting that I've broken it out into sections. Note that while developing this patch I discovered a Subtle Bug in CPython, which I have discussed in its own section below. ____________ THE OVERVIEW I don't remember where I picked it up, but I remember reading years ago that the simple, obvious Python approach for string concatenation: x = "a" + "b"
0
1424
by: AndyL69 | last post by:
Hello I've got a very strange Problem. When im adding a new ACE entry to a UNC Direcotry the inherented ACL's will be lost. When I'm adding a new ACE to a directory / file in this UNC path the inherented ACE are still available. What's wrong ? I don't understand the difference between \\server\share and \\server\share\directory while adding a ACE AndyL Sample: \\myserver\myshare Inherited ACE: Administrators, Network Service
3
2017
by: dmj07 | last post by:
Hi, I need some help in creating a dataset that I can bind to a datalist after it has added a set of strings to it: DataSet ds = new DataSet(); DataTable dt = new DataTable("table"); ds.Tables.Add(dt); dt.Columns.Add("id"); dt.Columns.Add("description"); dt.Columns.Add("price");
1
1376
by: mwcapps | last post by:
I've got 2 labels (lblDSPCash and lblLCash) that are setup: Format(dsDSPCash.Tables("dspcash").Rows(0)("dspcash"), "Currency") and Format(dsLCash.Tabls("localcash").Rows(0)("lcash"), "Currency") My 3rd label (lblTCash) is supposed to be a 'sum' of the other two. I've tried the following code but it rounds to the nearest dollar:
0
9697
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
10291
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
10260
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
9100
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...
1
7589
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6827
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
5616
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4156
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2956
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.