[PHP5] null voranstellen

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • [PHP5] null voranstellen

    hallo zusammen,

    ich wollte eine funktion basteln die falls eine variable kleiner 10 ist, eine null voranstellt.
    also 01 02 03 usw.

    jetzt ist aber das problem dass 01 auch kleiner zehn ist und ich dann 001 bekomme. das will ich aber nicht bzw. das will ich verhindern.
    bloss leider hab ich keine ahnung wie das funktionieren koennte.
    kann mir jemand einen tip geben nach was ich suchen muss?!
    oder vielleicht sogar mir nen scrip geben

    danke vielmals.


    PHP Code:

    ##########################
    #wenn kleiner zehn dann null voranstellen
    ##########################
    function formatZahl($zahl){

      if (
    $zahl 10)
          {return 
    "0" $zahl;} 
      else {return 
    $zahl;}


    www.flyer4fun.de

  • #2
    sprintf()
    number_format()

    Comment


    • #3
      oder wenn du es wirklich so komisch machen willst...

      PHP Code:
      function formatZahl($zahl) {
         if (
      $zahl 10) { return "0".((int)$zahl); } 
         else { return 
      $zahl; }

      Comment


      • #4
        suche nach führende null(en)

        Comment


        • #5
          nur das hier ist wirklich sinnvoll!

          Original geschrieben von penizillin
          sprintf()
          number_format()
          INFO: Erst suchen, dann posten![color=red] | [/color]MANUAL(s): PHP | MySQL | HTML/JS/CSS[color=red] | [/color]NICE: GNOME Do | TESTS: Gästebuch[color=red] | [/color]IM: Jabber.org |


          Comment


          • #6
            sorry das ich mich erst jetzt melde.
            ich danke euch ihr habt mir geholfen!
            www.flyer4fun.de

            Comment

            Working...
            X