PHP: script che converte i numeri decimali in binari

Come da titolo, ecco un piccolo scrip in php che converte i numeri decimali in binari:

<?php
$stringa=$_POST['stringa'];
if(!isset($stringa))
{
    echo"Devi inserire il numero da convertire<br>";
    echo"<A href="javascrip:history.back()">Torna indietro</A><br>";
    die();
}
if(!ereg("^[0-9]*$", $stringa))
{
    echo"Hai inserito caratteri non validi (solo valori numerici positivi)<br>";
    echo"<A href="javascrip:history.back()">Torna indietro</A><br>";
    die();
}
if($stringa>255)
{
    echo"Devi inserire un valore valido (max 255)<br>";
    echo"<A href="javascrip:history.back()">Torna indietro</A><br>";
    die();
}
$risultato=decbin($stringa);
echo"Il valore corrispondente è $risultato<br>";
?>

Il codice HTML è il seguente:

<html>
 <head>
 <title>Converter</title>
 </head>
 <body>
 <form action="Converter.php" method="POST">
 <fieldset>
     <legend> Inserisci il valore decimale da convertire in binario (max 256) </legend>
     <input type="text" name="stringa" id="stringa" />
     <input type="submit" name="submit" value="invia" />
 </fieldset>
 </form>
 </body>
 </html>

A presto. 

 

PHP: script che converte i numeri decimali in binariultima modifica: 2008-06-11T10:00:00+02:00da nazarenolatella
Reposta per primo quest’articolo