Glue together variable and string

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • helgefredheim@gmail.com

    Glue together variable and string

    How do I glue together a variable with a string?

    $suffix = "px";

    $height = 14;

    I need to print "14px" widthout any whitespace inbetween 14 and px. How
    do I do it?

  • Andy Hassall

    #2
    Re: Glue together variable and string

    On Tue, 28 Feb 2006 20:38:00 -0000, Krustov <krusty@krustov .co.uk.INVALID>
    wrote:
    [color=blue]
    ><comp.lang.p hp , , helgefredheim@g mail.com>
    ><1141158879.32 9609.168420@u72 g2000cwu.google groups.com>
    ><28 Feb 2006 12:34:39 -0800>
    >[color=green]
    >> $suffix = "px";
    >>
    >> $height = 14;
    >>
    >> I need to print "14px" widthout any whitespace inbetween 14 and px. How[/color]
    >
    >$thc="$suffi x" . "$height";[/color]

    The double-quotes are pointless here, but otherwise correct.

    If you wanted to use double quotes, an alternative is:

    $thc = "$suffix$height ";

    The OP should read: http://uk.php.net/manual/en/language.types.string.php

    --
    Andy Hassall :: andy@andyh.co.u k :: http://www.andyh.co.uk
    http://www.andyhsoftware.co.uk/space :: disk and FTP usage analysis tool

    Comment

    • Andy Hassall

      #3
      Re: Glue together variable and string

      On Tue, 28 Feb 2006 22:07:40 -0000, Krustov <krusty@krustov .co.uk.INVALID>
      wrote:
      [color=blue]
      ><comp.lang.p hp , Andy Hassall , andy@andyh.co.u k>
      ><hcd902d0kedvf uc7g39keq5rbk8a qs15mr@4ax.com>
      ><Tue, 28 Feb 2006 20:43:20 +0000>
      >[color=green][color=darkred]
      >>> $thc="$suffix" . "$height";[/color]
      >>
      >> The double-quotes are pointless here, but otherwise correct.[/color]
      >
      >People like you never answer simple questions like this - unless its to
      >point out or correct what somebody has said .[/color]

      So, bad replies should go uncorrected? Hopefully both the OP, and the person
      who replied with a nearly correct but not quite right answer, learned
      something.
      [color=blue]
      >X-no-archive: yes[/color]

      What's the point in self-destructing replies, by the way?

      --
      Andy Hassall :: andy@andyh.co.u k :: http://www.andyh.co.uk
      http://www.andyhsoftware.co.uk/space :: disk and FTP usage analysis tool

      Comment

      • noone

        #4
        Re: Glue together variable and string

        Krustov wrote:[color=blue]
        > <comp.lang.ph p , Andy Hassall , andy@andyh.co.u k>
        > <8uk902h1cbroup jij78as2q689r27 35rg6@4ax.com>
        > <Tue, 28 Feb 2006 22:54:16 +0000>
        >[color=green][color=darkred]
        >>>>>$thc="$suf fix" . "$height";
        >>>>
        >>>>The double-quotes are pointless here, but otherwise correct.
        >>>
        >>>People like you never answer simple questions like this - unless its to
        >>>point out or correct what somebody has said .[/color]
        >>
        >> So, bad replies should go uncorrected? Hopefully both the OP, and the person
        >>who replied with a nearly correct but not quite right answer, learned
        >>something.
        >>[/color]
        >
        >
        > Hopefully you will now start to answer simple questions like the one
        > posted all by yourself to prevent future occurrences .
        >
        > Enough simple questions get asked on here and you wont go short of
        > opportunitys .[/color]

        opportunities that we answer and answer and answer and answer......... .

        give someone a fish he eats today - teach him to fish and he eats for a
        lifetime.

        Pointing out where the docs are can be an invaluable lesson. I have not
        yet come across a problem I can solve myself by simply RTM ( and google
        doesn't hurt).

        Comment

        • Iván Sánchez Ortega

          #5
          Re: Glue together variable and string

          -----BEGIN PGP SIGNED MESSAGE-----
          Hash: SHA1

          Krustov wrote:
          [color=blue][color=green][color=darkred]
          >>>$thc="$suffi x" . "$height";[/color]
          >>
          >> The double-quotes are pointless here, but otherwise correct.[/color]
          >
          > How pointless is that ? .[/color]

          Just pointless.

          Using double-quotes in that scenario will just increase the parsing time. If
          you want to concatenate two (mixed) variables into one string, just use the
          "." operator. That will make an implicit variable casting of any numeric
          (integer or float) variables to string, with no need to use any quotes or
          explicit casting:

          $thc = $height . $suffix;

          And, BTW: KISS.

          - --
          - ----------------------------------
          Iván Sánchez Ortega -i-punto-sanchez--arroba-mirame-punto-net

          El que las hace, las imagina.

          -----BEGIN PGP SIGNATURE-----
          Version: GnuPG v1.4.2 (GNU/Linux)

          iD8DBQFEBWag3jc Q2mg3Pc8RApfFAJ 9xauBkL6tMS4D/z0oToUG8WFEJLQC fSnpC
          z2mmzPVLqRGUt1S 8JDCkzIg=
          =DeIU
          -----END PGP SIGNATURE-----

          Comment

          Working...