$balises = array(
1 => array("<h1>", "</h1">"),
6 => array("<h6>","</h6"),
);
$texte_balise = "";
$nb_balises = count($balises);
if (($nombre < 1) ou ($nombre > $nb_balise)) //ou >=
{
}
else
{
}
return $texte_balise;Code : Tout sélectionner
function txt2Html($index,$str){
$tab = array(
'<div>'.$str.'</div>',
'<p>'.$str.'</p>',
'<h1>'.$str.'</h1>',
'<h2>'.$str.'</h2>',
);
return $tab[$index];
}
echo txt2Html(1,'Salut');
Code : Tout sélectionner
function txt2Html($tag,$str){
$tags = array('div','p','h1','h2');
$tab = array(
'<div>'.$str.'</div>',
'<p>'.$str.'</p>',
'<h1>'.$str.'</h1>',
'<h2>'.$str.'</h2>',
);
return in_array($tag,$tags) ? $tab[array_search($tag,$tags)] : '';
}
echo txt2Html('p','Salut');
Code : Tout sélectionner
<?php
function format_code($string, $tag)
{
$tags = array('div', 'p', 'h1', 'h2');
$formatted = sprintf("<%s>%s</%s>",$tags["$tag"], $string, $tags["$tag"]);
return $formatted;
}
echo format_code("coucou", 2);
?>regarde ma dernière réponse, tu as une améioration avec la correction de ma première solutionMerci beaucoup niuxe, ça fonctionne ! Et en plus j'ai compris les erreurs que je faisais.
C'est un début pour un helper. Je t'avoue que c'est pas très évolué comme exo.Exercice d'une utilité phénoménale...