SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    Confirmed Halfwit
    Join Date
    Oct 1999
    Location
    Vancouver, BC, Canada
    Posts
    983
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Does anyone know how to continuously add new information to an existing variable?

    For example, let's say I have a variable call $var and I give it a value of "Hello".

    $var = "Hello";

    Now I want to make the value to be "Hello There", but I only want to add the " There" part, not replace the existing string. This example might explain what I want to do:

    $var = $var + " There";

    So after this, if I echo $var to screen I would have "Hello There".

    Make sense? Does anyone know how to do this?
    - A simple online WYSIWYG editor for HTML code snippets.
    - Managed Web Hosting - $3.95/month (resellers welcome)
    - Why pay more? $8.95 domains & $9.95 SSL certificates!

  2. #2
    SitePoint Wizard
    Join Date
    Jul 1999
    Location
    Chicago
    Posts
    2,629
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Well, since $i += 6; means $i = $i + 6;, in Perl you can do this:

    $var .= "Hello";

    Which means $var = $var . "Hello";. And each line can be like that. It should work in PHP, as far as I know.

  3. #3
    SitePoint Enthusiast
    Join Date
    Feb 2001
    Posts
    58
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Yes that works in php

    $var = "Hello";

    $var .= " there.";

    echo $var;

    will output Hello there. to the browser.
    Marty H.

  4. #4
    ********* Callithumpian silver trophy freakysid's Avatar
    Join Date
    Jun 2000
    Location
    Sydney, Australia
    Posts
    3,798
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Its refered to as string concatenation (from concatenate). Isn't that a beautiful word?


Bookmarks

Posting Permissions

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