Store printf value inside variable?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Boo

    Store printf value inside variable?

    Using printf, I can get the output I want:

    printf("ch:\t6% u\n",$ch);

    The %u allows me to convert a negative value to an unsigned decimal
    number.

    My problem is that I don't want to output this to the screen. I need
    to store it as a variable. Is there any way to do this? Thanks!

  • Ken Robinson

    #2
    Re: Store printf value inside variable?


    Boo wrote:[color=blue]
    > Using printf, I can get the output I want:
    >
    > printf("ch:\t6% u\n",$ch);
    >
    > The %u allows me to convert a negative value to an unsigned decimal
    > number.
    >
    > My problem is that I don't want to output this to the screen. I need
    > to store it as a variable. Is there any way to do this? Thanks![/color]

    Take a look at sprintf() <http://www.php.net/sprintf/>

    Ken

    Comment

    • BKDotCom

      #3
      Re: Store printf value inside variable?

      Have you looked at the manual?
      See also http://www.php.net/sprintf

      same as printf, only returns the string

      Comment

      • Uncle Pirate

        #4
        Re: Store printf value inside variable?

        Boo wrote:[color=blue]
        > Using printf, I can get the output I want:
        >
        > printf("ch:\t6% u\n",$ch);
        >
        > The %u allows me to convert a negative value to an unsigned decimal
        > number.
        >
        > My problem is that I don't want to output this to the screen. I need
        > to store it as a variable. Is there any way to do this? Thanks!
        >[/color]

        I'm new to PHP so can't absolutely answer your question. But, as I
        understand it, PHP was designed taking ideas and methods from Perl, C++,
        and various other languages. Most all have an sprintf function. Search
        the manual for sprintf and I'll bet you've found exactly what you are
        looking for.

        --
        Stan McCann "Uncle Pirate" http://stanmccann.us/pirate.html
        Webmaster/Computer Center Manager, NMSU at Alamogordo
        Coordinator, Tularosa Basin Chapter, ABATE of NM; AMA#758681; COBB
        '94 1500 Vulcan (now wrecked) :( http://motorcyclefun.org/Dcp_2068c.jpg
        A zest for living must include a willingness to die. - R.A. Heinlein

        Comment

        • Uncle Pirate

          #5
          Re: Store printf value inside variable?

          Ken Robinson wrote:[color=blue]
          > Boo wrote:
          >[color=green]
          >>Using printf, I can get the output I want:
          >>
          >>printf("ch:\t 6%u\n",$ch);
          >>
          >>The %u allows me to convert a negative value to an unsigned decimal
          >>number.
          >>
          >>My problem is that I don't want to output this to the screen. I need
          >>to store it as a variable. Is there any way to do this? Thanks![/color]
          >
          >
          > Take a look at sprintf() <http://www.php.net/sprintf/>
          >
          > Ken
          >[/color]

          I should have read on before my initial reply, I knew there had to be an
          sprintf funtion.

          --
          Stan McCann "Uncle Pirate" http://stanmccann.us/pirate.html
          Webmaster/Computer Center Manager, NMSU at Alamogordo
          Coordinator, Tularosa Basin Chapter, ABATE of NM; AMA#758681; COBB
          '94 1500 Vulcan (now wrecked) :( http://motorcyclefun.org/Dcp_2068c.jpg
          A zest for living must include a willingness to die. - R.A. Heinlein

          Comment

          Working...