1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50
|
<?php
if(!isset($_POST['txt']))
{
$ligne = file_get_contents("test1.2.php");
echo'<form method="post" action="test.php">
<p>
<label for="txt">Comment pensez-vous que je pourrais améliorer mon site ?</label><br />
<textarea name="txt" id="txt" rows="40" cols="200" >'.$ligne.'</textarea>
<input type="submit" />
</p>
</form>';
}
else
{
$monfichier1 = fopen("c://wamp//www//TEST//creertuto//test1.1.php", "w+");
function AddHTML($capt)
{
return '[HTML]'.str_replace(PHP_EOL, '[/HTML]'.PHP_EOL.'[HTML]', $capt[1]).'[/HTML]';
}
function AddCSS($capt)
{
return '[CSS]'.str_replace(PHP_EOL, '[/CSS]'.PHP_EOL.'[CSS]', $capt[1]).'[/CSS]';
}
$texte = $_POST['txt'];
$texte = htmlspecialchars($texte);
$texte = nl2br($texte);
$texte = preg_replace_callback('`\[CSS](.+)\[/CSS]`sU', 'AddCSS', $texte);
// Regex CSS
$texte = preg_replace('#(\[CSS\].*)(.*?):(.*\[/CSS\])#', '<SPAN CLASS="balisecsstype">$1$2</SPAN>:$3', $texte);
$texte = preg_replace('#(\[CSS\].*):(.*?);(.*\[/CSS\])#', '$1:<SPAN CLASS="balisecssname">$2</SPAN>;$3', $texte);
$texte = preg_replace('#(\[CSS\].*)\.(.*?)(.*\[/CSS\])#', '$1.<SPAN CLASS="balisecssclass">$2$3</SPAN>', $texte);
$texte = preg_replace('#(\[CSS\].*)\#(.*?)(.*\[/CSS\])#', '$1#<SPAN CLASS="balisecssid">$2$3</SPAN>', $texte);
//comentaire CSS
$texte = preg_replace('#(\[CSS\].*)/\*(.*?)\*/(.*\[/CSS\])#', '$1 <span class="balisecsscom">/* $2 */</span>$3', $texte);
// je supprime les balises CSS
$texte = preg_replace('#\[CSS\](.*)\[/CSS\]#','$1', $texte);
fputs($monfichier1, $texte);
fclose($monfichier1);
?> |