Find the answer to your Linux question:
Results 1 to 5 of 5
I'm reading the PHP manual and it states that I can't use theh '+' operator to concatenate strings. It was recommened that I use the '.' operator instead. After testing ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1
    Linux Engineer
    Join Date
    Nov 2002
    Location
    Queens, NY
    Posts
    1,319

    String concatenation


    I'm reading the PHP manual and it states that I can't use theh '+' operator to concatenate strings. It was recommened that I use the '.' operator instead. After testing both of these, it seems to work just fine. Am not reading the manual correctly?
    The best things in life are free.

  2. #2
    Linux Guru
    Join Date
    Oct 2001
    Location
    Täby, Sweden
    Posts
    7,578
    The + operator doesn't work at all for me to concatenate strings; it just tries to add them as numbers. If I run print("a" + "b"), it outputs "0".

  3. #3
    Linux Engineer
    Join Date
    Nov 2002
    Location
    Queens, NY
    Posts
    1,319
    How about:
    Code:
    $name = "first" + " name";
    This definitely works for me.
    The best things in life are free.

  4. #4
    Linux Guru
    Join Date
    Oct 2001
    Location
    Täby, Sweden
    Posts
    7,578
    Code:
    $name = "first" + "name ";
    print($name);
    That gives the output 0.
    I've tried it on both PHP 4.2.2 and 4.3.2. What version are you using?

  5. #5
    Linux Engineer
    Join Date
    Nov 2002
    Location
    Queens, NY
    Posts
    1,319
    Yea,

    I was looking at my code wrong. The dot operator is the concat operator for strings.
    The best things in life are free.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •