Bonjour, voila je suis sous un serveur ayant comme capacité :
phpMyAdmin - 2.11.11.1
MySQL client version: 4.1.14
Used PHP extensions: mysql
Mon jeu fonctionne plutot bien ormis une erreur qui est fatal et que nous n'arrivont pas a regler.
Parse error: syntax error, unexpected '(', expecting T_OLD_FUNCTION or T_FUNCTION or T_VAR or '}' in /usr/home/flozza83/domains/flozza83.com/public_html/Minecraft-Gamers/classes/templates2.class.php on line 4
voici donc le code en question :
<?php
//Pour récupérer le template à la fin : recuptpl()
class Tpl
{(
private $tpl;
private $blocs;
private $contenu_blocs;
private $dossier_cache;
private $temps_cache;
)
// Charge le template donné
public function fichier($fichier)
{
if (file_exists($fichier))
{
$this->dossier_cache = 'cache/';
$this->temps_cache = '600'; // Le cache est valable 10 minutes
$this->tpl = file_get_contents($fichier);
$this->blocs = array();
$this->contenu_blocs = array();
}
else
{
die('<b>
<font color="red">ERREUR TPL :</font>
<font color="darkorange">Problème lors de la récupération du fichier =></font>
<font color="blue">'.$fichier.'</font>
</b>
');
}
}
/* Assigne une variable simple au template ou un tableau de variables
* Côté Template :
<div>{TITRE}</div>
<table>
<tr>
<td>{TITRE2}</td>
<td>{TEXTE}</td>
</tr>
</table>
* Côté php :
$tpl->assign('TITRE', 'Exemple');
$tpl->assign(array(
'TITRE2' => 'Exemple2',
'TEXTE' => 'Test de la fonction assign'
));
*/
public function assign($variable, $valeur = '')
{
$rechercher = array();
$remplacer = array();
if (is_array($variable))
{
foreach ($variable AS $cle => $valeur)
{
$rechercher[] = '{' . $cle . '}';
$remplacer[] = $valeur;
}
}
else
{
$rechercher[] = '{' . $variable . '}';
$remplacer[] = $valeur;
}
$this->tpl = str_replace($rechercher, $remplacer, $this->tpl);
}
/* Permet de placer un bloc conditionnel et ses variables
* Côté Template :
<!--MONBLOC-->
<table>
<tr>
<td>{NOM}</td>
<td>{DESCRIPTION}</td>
</tr>
</table>
<!--/NOMBLOC-->
* Côté PHP :
$tpl->bloc("NOMBLOC", array("NOM" => $nom, "DESCRIPTION" => $description));
*/
public function bloc($nom_bloc, $tableau)
{
$array_recherche = array('<!--' . $nom_bloc . '-->', '<!--/' . $nom_bloc . '-->');
$array_remplace = array('', '');
if (!isset($this->blocs[$nom_bloc]))
{
$tableau_ereg = array();
ereg('<!--' . $nom_bloc . '-->(.*)<!--/' . $nom_bloc . '-->', $this->tpl, $tableau_ereg);
$this->blocs[$nom_bloc] = $tableau_ereg[0];
if(empty($tableau_ereg[0]) ) // Dans le cas ou le bloc n'a pas été trouvé, on bloc la page en affichant une erreur
{
die('<b>
<font color="red">ERREUR TPL :</font>
<font color="darkorange">Impossible de recuperer le bloc demandé =></font>
<font color="blue">'.$nom_bloc.'</font>
</b>
');
}
}
while (list($cle, $valeur) = each($tableau))
{
$array_recherche[] = '{' . $cle . '}';
$array_remplace[] = $valeur;
}
if (!isset($this->contenu_blocs[$nom_bloc]))
{
$this->contenu_blocs[$nom_bloc] = str_replace($array_recherche, $array_remplace, $this->blocs[$nom_bloc]);
}
else
{
$this->contenu_blocs[$nom_bloc] .= str_replace($array_recherche, $array_remplace, $this->blocs[$nom_bloc]);
}
}
/* Très utile pour les boucles, assigne en boucle les variables stockées dans $tag_array
* Côté Template :
<table>
{BALISE id=1}
<tr>
<td>{NOM}</td>
<td>{DESCRIPTION}</td>
</tr>
{/BALISE}
</table>
* Côté PHP :
$sql = 'SELECT nom, description FROM test';
$reponse = mysql_query($sql);
$nom = array();
$description = array();
while ($donnees = mysql_fetch_array($reponse))
{
$nom[] = $donnees['nom'];
$description[] = $donnees['description'];
}
$global = array('NOM' => $nom, 'DESCRIPTION' => $description);
$tpl->assigntag('BALISE', '1', $global);
*/
public function assigntag($tag, $id, $tableau)
{
if ($this->veriftableau($tableau))
{
reset($tableau);
$nom_cle = count($tableau);
$nom_valeur = count($tableau[key($tableau)]);
$tmp = $this->trouvertag($tag, $id);
for ($i = 0; $i < $nom_valeur; $i++)
{
$tab[$i] = $tmp;
reset($tableau);
for ($j = 0; $j < $nom_cle; $j++)
{
$tab[$i] = str_replace('{' . key($tableau) . '}', $tableau[key($tableau)][$i], $tab[$i]);
next($tableau);
}
}
for ($i = 1; $i < count($tab); $i++)
{
$tab[0] .= $tab[$i];
}
$remplacer = '{' . $tag . ' id=' . $id . '}' . $tmp . '{/' . $tag . '}';
$this->tpl = str_replace($remplacer, $tab[0], $this->tpl);
}
else
{
die("Attention! Erreur dans la taille des tableaux de la balise $tag id=$id");
}
}
/* Permet de supprimer dynamiquement un bloc
* Côté Template :
<!--BLOC1-->
<table>
<tr>
<td>{ERREUR}</td>
</tr>
</table>
<!--/BLOC1-->
...
* Côté PHP :
if ($erreur)
{
$tpl->bloc("BLOC1", array ("ERREUR" => "Texte à afficher en cas d'erreur."));
}
else
{
$tpl->supprime_bloc('BLOC1');
}
*/
public function supprime_bloc($nom_bloc)
{
$this->tpl = preg_replace(''<!--' . $nom_bloc . '-->(.+?)<!--/' . $nom_bloc . '-->'sim', '', $this->tpl);
}
// Affiche le template et gère le cache
public function afficher()
{
$debut = microtime();
$fichier_cache = $this->dossier_cache . md5($_SERVER['REQUEST_URI']);
$interval = time() - @filemtime($fichier_cache);
if (file_exists($fichier_cache) && ($interval < $this->temps_cache) && (isset($GLOBALS['set_to_cache'])))
{
echo "<!-- LU A PARTIR DU CACHE -->";
readfile ($fichier_cache);
$fin = microtime();
$total = (integer)(($fin - $debut) * 1000);
if ($total < 0) $total = 0;
echo "<!-- TEMPS D'EXECUTION : " . $total . " -->";
}
else
{
echo "<!-- CALCULE SANS CACHE -->";
echo $this->recuptpl();
$fin = microtime();
$total = (integer)(($fin - $debut) * 1000);
if ($total < 0) $total = 0;
echo "<!-- TEMPS D'EXECUTION : " . $total . " -->";
}
}
// Fonction permettant de récupérer le texte entre deux balises
private function trouvertag($tag, $id, $option = "")
{
if (empty($option))
{
//retourne la chaine si il la trouvé et rien sinon
@preg_match("/(\{" . $tag . " id=)(" . $id . ")(})(.*?)(\{\/" . $tag . "})/ism", $this->tpl, $resultat);
if (empty($resultat[4]))
{
preg_match("/\{" . $tag . " id=(" . $id . ")}/ism", $this->tpl, $resultat);
return $resultat[1];
}
return $resultat[4];
}
elseif ($option == "SELECTED")
{
//retourne le nom selected si il la trouvé et rien sinon
@preg_match("/\{" . $tag . " id=" . $id . " selected=(.*?)}/ism", $this->tpl, $resultat);
return @$resultat[1];
}
else
{
return 0;
}
}
// Test s'il y a le même nombre d'éléments dans les sous-tableaux array(key => array(), key => array())
private function veriftableau($tableau)
{
reset($tableau);
$retour = true;
$numero = count($tableau[key($tableau)]);
for ($i = 0; $i < count($tableau); $i++)
{
if ($numero != count($tableau[key($tableau)]))
{
$retour = false;
}
next($tableau);
}
return $retour;
}
oliopur
Messages postés11Date d'inscriptionmardi 5 janvier 2010StatutMembreDernière intervention24 mars 2012 24 mars 2012 à 20:21
apparament rien ne cloche dans les ouvertures et fermetures () {}...
Il faut chercher ailleur, es tu sur que ton interpreteur accepte les commentaires // sur la meme ligne que le code ?, moi il ne les supporte pas !!!
Parse error: syntax error, unexpected T_STRING, expecting '{' in /usr/home/flozza83/domains/flozza83.com/public_html/Minecraft-Gamers/classes/templates2.class.php on line 5
Trouvez des réponses à vos questions sur les langages, les frameworks et les astuces de codage. Échangez avec d'autres développeurs passionnés pour améliorer vos compétences en programmation et rester au fait des dernières tendances du secteur.