PHP Tutorial: ASCII Datenbanken
ASCII Datenbanken sind eigentlich nur Textdateien, in denen man Daten speichert, die durch ein Trennzeichen voneinander getrennt sind. Dieses Tutorial zeigt wie es geht. Mit Übung und Lösung
|13.10.2002 |
deep_space_nine@ |
22728 | KAT : PHP |
|
0
11
12
7. Lösungsvorschläge zu den Übungen
4. Aufgabe
<html>
<body>
<table border cellpadding=0 cellspacing=0>
<?php
// Den Parameter mit script.php?show=param&suchname=name
// Mögliche parameter: name, tel
// name durch den entsprechenden parameter ersetzen
// Suchname angeben ...
if(! $suchname ) $suchname = "" ;
$suchname = strtolower ( $suchname );
function my_decrypt ( $txt )
{
$txt = strtolower ( $txt );
$txt = str_replace ( "10 " , "j" , $txt );
$txt = str_replace ( "11 " , "k" , $txt );
$txt = str_replace ( "12 " , "l" , $txt );
$txt = str_replace ( "13 " , "m" , $txt );
$txt = str_replace ( "14 " , "n" , $txt );
$txt = str_replace ( "15 " , "o" , $txt );
$txt = str_replace ( "16 " , "p" , $txt );
$txt = str_replace ( "17 " , "q" , $txt );
$txt = str_replace ( "18 " , "r" , $txt );
$txt = str_replace ( "19 " , "s" , $txt );
$txt = str_replace ( "20 " , "t" , $txt );
$txt = str_replace ( "21 " , "u" , $txt );
$txt = str_replace ( "22 " , "v" , $txt );
$txt = str_replace ( "23 " , "w" , $txt );
$txt = str_replace ( "24 " , "x" , $txt );
$txt = str_replace ( "25 " , "y" , $txt );
$txt = str_replace ( "26 " , "z" , $txt );
$txt = str_replace ( "1 " , "a" , $txt );
$txt = str_replace ( "2 " , "b" , $txt );
$txt = str_replace ( "3 " , "c" , $txt );
$txt = str_replace ( "4 " , "d" , $txt );
$txt = str_replace ( "5 " , "e" , $txt );
$txt = str_replace ( "6 " , "f" , $txt );
$txt = str_replace ( "7 " , "g" , $txt );
$txt = str_replace ( "8 " , "h" , $txt );
$txt = str_replace ( "9 " , "i" , $txt );
$txt = str_replace ( "_" , " " , $txt );
return $txt ;
}
if(! $show ) $show = "name" ;
switch( $show )
{
case "name" : $t = 0 ;
break;
case "tel" : $t = 1 ;
break;
default : $t = 2 ;
break;
}
$datei = "./db.store" ;
$trennzeichen = "," ;
if( file_exists ( $datei ))
{
$zeile = file ( $datei );
for( $i = 0 ; $i < sizeof ( $zeile ); $i ++)
{
if(( $zeile [ $i ] != "" )&&( $zeile [ $i ] != "n" ))
{
$eintrag = explode ( $trennzeichen , $zeile [ $i ]);
if( my_decrypt ( $eintrag [ 0 ]) == $suchname )
{
echo "<tr>" ;
echo "<td>" . my_decrypt ( $eintrag [ 0 ]). "</td>" ;
echo "<td>" . $eintrag [ 1 ]. "</td>" ;
echo "</tr>" ;
}
}
}
}
?>
</table>
</body>
</html>
Über den Autor
Status
Premium Mitglied
Beruf
Unbekannt
Mitglied seit:
30.04.2009
letzte Aktivität
04.06.2009
Tutorial bewerten
Hat Ihnen dieses Tutorial gefallen? Dann bewerten Sie es jetzt! Fünf Sterne bedeutet "Sehr gut", ein Stern "Unzureichend".