473,394 Members | 1,759 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.

concatanate 2 strings

Can someone please tell me how to concatanate to strings like this
please
$name = $_POST["Name"];
$from = $_POST["Email"];

$headers = "From: $name $from\r\n";

i beleve in C there is a strcat() is this similar.
if so is there an online site for PHP function.

Desmond.

Jul 17 '05 #1
6 3163
"Desmond" wrote:
Can someone please tell me how to concatanate to strings like this
please
$name = $_POST["Name"];
$from = $_POST["Email"];

$headers = "From: $name $from\r\n";


Did you try that? It ought to work exactly as you wrote it.

However, if you want a valid "From" header, put the email address in angle
brackets like this:

$headers = "From: $name <$from>\r\n";

And please check that the $_POST[] data is valid. For example, check that
the email address is correctly formatted, and that the "Name" data doesn't
contain any newline characters. You might also need to apply stripslashes()
to the data from your form.

The PHP documentation is here: <http://www.php.net/docs.php>

--
phil [dot] ronan @ virgin [dot] net
http://vzone.virgin.net/phil.ronan/
Jul 17 '05 #2
On 2005-06-20, Desmond <pd*******@hotmail.com> wrote:
Can someone please tell me how to concatanate to strings like this
please
$name = $_POST["Name"];
$from = $_POST["Email"];

$headers = "From: $name $from\r\n";

i beleve in C there is a strcat() is this similar.
if so is there an online site for PHP function.


In PHP the concatenation operator is the dot. So you can concatenate two
strings like:

$concatenated = $string1.$string2;

This is also described in the manual (which is really a great ressource
for PHP developers):

<http://www.php.net/manual/en/language.types.string.php>

--
Cheers,
- Jacob Atzen
Jul 17 '05 #3
Thanks I have seen some code on the internet and it uses a full stop

$aaa . $bbb

and I have seen $zzz .= $vvvv is the .= rthe equivelent as +=

Desmond.

Jul 17 '05 #4
"Desmond" <pd*******@hotmail.com> kirjoitti
viestissä:11*********************@o13g2000cwo.goog legroups.com...
Thanks I have seen some code on the internet and it uses a full stop

$aaa . $bbb
That works too.
and I have seen $zzz .= $vvvv is the .= rthe equivelent as +=


That also works.

Full stop is the concatenation operator, but php also has the quite unique
mechanism for inserting variables directly into strings.

$foo .= $bar;
is just short for
$foo = $foo . $bar; and they both concatenate the two variables.
But this works as well, just in a slightly different way:
$foo = "$foo$bar";

Variables inside double qoutes are replaced with their values. inside single
qoutes they'r not evaluated, but interpreted literally.

--
"I am pro death penalty. That way people learn
their lesson for the next time." -- Britney Spears

et****************@5P4Mgmail.com
Jul 17 '05 #5

Not wanting to repeat what has been written, but I think someone should
point out that the concatenation of global variables has to be done with the
.. (dot) operator, whereas using local variables, like you have, you can
directly stick strings together _or_ use the . operator.

So these are all ok:

$bigstring = "$first $second";
$bigstring = "$first some non variable text $second";
$bigstring = $first . $second;
$bigstring = $first . " some non variable text " . $second;

But with globals only . concatenation is ok:

$bigstring = $_POST['Name'] . $_POST['Email'];
$bigstring = "normal text with $localvariable" . $_POST['Name'] . "more
text";

(above code has not been tested in real-life) :>

Luke

"Desmond" <pd*******@hotmail.com> wrote in message
news:11*********************@f14g2000cwb.googlegro ups.com...
Can someone please tell me how to concatanate to strings like this
please
$name = $_POST["Name"];
$from = $_POST["Email"];

$headers = "From: $name $from\r\n";

i beleve in C there is a strcat() is this similar.
if so is there an online site for PHP function.

Desmond.

Jul 17 '05 #6
"luke" <ld*******@eml.nope> wrote in message
news:ul*******************@news.xtra.co.nz...

Not wanting to repeat what has been written, but I think someone should
point out that the concatenation of global variables has to be done with the . (dot) operator, whereas using local variables, like you have, you can
directly stick strings together _or_ use the . operator.

So these are all ok:

$bigstring = "$first $second";
$bigstring = "$first some non variable text $second";
$bigstring = $first . $second;
$bigstring = $first . " some non variable text " . $second;

But with globals only . concatenation is ok:

$bigstring = $_POST['Name'] . $_POST['Email'];
$bigstring = "normal text with $localvariable" . $_POST['Name'] . "more
text";

(above code has not been tested in real-life) :>


This is fine and works perfectly (you can drop the quotes around the key
name when inside double quotes):

$localvariable = 'white background';
//$_POST['Name'] previously set to 'John'
$bigstring = "normal text with $localvariable for $_POST[Name] to read.";

outputs: normal text with white background for John to read.

and...

$localvariable = 'white background';
//$_POST['Name'] previously set to 'John'
$bigstring = "normal text with $localvariable for '$_POST[Name]' to read.";

outputs: normal text with white background for 'John' to read.
Norm
--
FREE Avatar hosting at www.easyavatar.com
Jul 17 '05 #7

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

Similar topics

20
by: Ravi | last post by:
Hi, I have about 200GB of data that I need to go through and extract the common first part of a line. Something like this. >>>a = "abcdefghijklmnopqrstuvwxyz" >>>b = "abcdefghijklmnopBHLHT"...
17
by: Gordon Airport | last post by:
Has anyone suggested introducing a mutable string type (yes, of course) and distinguishing them from standard strings by the quote type - single or double? As far as I know ' and " are currently...
16
by: Paul Prescod | last post by:
I skimmed the tutorial and something alarmed me. "Strings are a powerful data type in Prothon. Unlike many languages, they can be of unlimited size (constrained only by memory size) and can hold...
4
by: agent349 | last post by:
First off, I know arrays can't be compared directly (ie: if (arrary1 == array2)). However, I've been trying to compare two arrays using pointers with no success. Basically, I want to take three...
25
by: Rainmaker | last post by:
Hi, Can anyone tell me an efficient algorithm to sort an array of strings? Keep in mind that this array is HUGE and so the algorithm should me efficient enough to deal with it. Thanks
25
by: sravishnu | last post by:
Hello, I have written a program to concatanae two strings, and should be returned to the main program. Iam enclosing the code, please give me ur critics. Thanks, main() { char s1,s2;...
2
by: Potiuper | last post by:
Question: Is it possible to use a char pointer array ( char *<name> ) to read an array of strings from a file in C? Given: code is written in ANSI C; I know the exact nature of the strings to be...
95
by: hstagni | last post by:
Where can I find a library to created text-based windows applications? Im looking for a library that can make windows and buttons inside console.. Many old apps were make like this, i guess ...
3
by: Peted | last post by:
Is it possible to concatanate a string and a byte array, into a "string" variable, send it as a string to an ip socket device and have the bytes, seen as a sequence of bytes, not char or string ? ...
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?
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...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
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
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
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...

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.