Hi,
wie kann hier meinen Code besser gestalten?
1. Wie kann ich den Aufruf der Funktion
"<?php getlang('%%str_sample1%%')?>"
abkürzen?
2. Und wie würde man unter PHP so was wegpacken, ich meine in eine "Userklasse" oder so. Damit es wiederverwendbar wird und die Seite sauberer wird. Was wäre professionell.
Code:
<?php
$servername = "localhost";
$username = "root";
$password = "poroot";
$port = "3306";
$db = "mm";
$verbidung = mysql_connect($servername, $username, $password)
or die ("Kann keine Verbindung zur Datenbank herstellen".mysql_error());
mysql_select_db($db);
function getlang($templatetext)
{
$array = explode ('%%str_', $templatetext);
echo $array[0];
for ($i=1; $i<count($array); $i++)
{
list ($ident, $tail) = explode('%%', $array[$i]);
$q = mysql_query ("select EN from t_lang_objects where IDENT='$ident'");
if ($q && $r = mysql_fetch_row($q))
echo $r[0];
else
echo $ident;
echo $tail;
}
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>
</head>
<body>
<?php getlang('%%str_sample1%%')?>
</body>
</html>
<?php
/* Verbindung schließen */
mysql_close($verbidung);
?>
gruß
yavuz