[Variablen] char umwandeln in int oder ???

Einklappen
X
 
  • Filter
  • Zeit
  • Anzeigen
Alles löschen
neue Beiträge

  • [Variablen] char umwandeln in int oder ???

    Mein Problem, in einer Tabelle sind noch alte Einträge (char) z.b. alt, neu oder nicht definiert ...
    jetzt will ich aber die bestehenden werte durch zahlen (int) ersetzten und meine script macht mir schwierigkeiten, da ich so nur nach int-werten ausgeben lassen kann, aber wie mache ich dem script klar, das ich

    if wert==char echo hier steht noch keine zahl drin !!!

    PHP-Code:

    if($wert==1){
            echo 
    "<option value=\"1\" selected> Zahl 1 </option>";
    }else{ 
            echo 
    "<option value=\"1\"> Zahl 1</option>";
    }
    if(
    $wert==0){
            echo 
    "<option value=\"0\" selected> Null </option>";
    }else{ 
            echo 
    "<option value=\"0\"> Null </option>";

    fotos :

    http://www.flickr.com/photos/rassloff/collections/

  • #2
    http://de3.php.net/manual/de/function.is-int.php
    http://de3.php.net/manual/de/function.is-string.php
    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 |


    Kommentar


    • #3
      wenn ich im script schreibe :
      PHP-Code:
              $inhalt ;
          
      $was is_int($inhalt) ; 
      dann wird das klar als ein int erkannt, aber wenn ich schreibe

      PHP-Code:
              $inhalt $eintrag // in eintrag steht eine 4
          
      $was is_int($inhalt) ; 
      dann wird es nicht erkannt ?!?!?!? wie soll ich dem script klar machen, das der wert ein int ist ???

      kann das daran liegen, das der wert aus einer DB kommt und das feld ein char-feld ist ???

      eventuell habe ich schon einen lösungsansatz, mit is_numeric()
      Zuletzt geändert von rossixx; 01.11.2005, 12:42.
      fotos :

      http://www.flickr.com/photos/rassloff/collections/

      Kommentar


      • #4
        kann das daran liegen, das der wert aus einer DB kommt und das feld ein char-feld ist ???
        gut erkannt. wer legt schon zahlen in der db in einem string-feld ab ....
        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 |


        Kommentar


        • #5
          PHP-Code:
          function is_strInt($data){
              
          $xy strtolower($data);
              
          $xy preg_replace("/\s*/"""$xy);
              
          $xy ereg_replace("\+"""$xy);
              if(
          strlen($xy) != strlen($inhalt))
              {
                  return 
          false;
              }
              elseif(
          is_numeric($xy) && !strpos($xy,".") &&
              !
          strpos($xy"e") && !strpos($xy,"x"))
              {
                  return 
          true;
              }
              else
              {
                  return 
          false;
              }

          Sollte nur true ergeben, wenn der String sich in einen Int überführen lässt

          Gruss

          tobi
          Gutes Tutorial | PHP Manual | MySql Manual | PHP FAQ | Apache | Suchfunktion für eigene Seiten

          [color=red]"An error does not become truth by reason of multiplied propagation, nor does truth become error because nobody sees it."[/color]
          Mohandas Karamchand Gandhi (Mahatma Gandhi) (Source)

          Kommentar

          Lädt...
          X