473,372 Members | 1,043 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,372 software developers and data experts.

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 49231
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*******************@fe02.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.andyhsoftware.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
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
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
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...
3
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...
14
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...
8
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
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. ...
0
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...
3
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");...
1
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"),...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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
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?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

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.