Nouveau sujet Répondre Imprimer Syndication RSS 2.0

coloration synthaxique du php...

Chef du projet FSB
Avatar de Genova
  • Age : 26 ans
  • Messages : 14944
  • Inscrit : 16 Septembre 2004
  Lien vers ce message 07 Décembre 2004, 22:12

Reprise du dernier message

Bah disons que si le mec utilise la balise PHP c'est pour le hillight de syntaxe, donc même si ca hillight du HTML tant mieux :)


Cause Im as free as a bird now, And this bird you can not change. - Freebird - Lynyrd Skynyrd
There's someone in my head but it's not me. - Brain damage - Pink Floyd
I said baby, you know Im gonna leave you. - Babe I'm gonna leave you - Led Zeppelin
Father ? yes son, I want to kill you - The end - The Doors
 
Flamme ardente
Avatar de bthivent
  • Age : 23 ans
  • Messages : 440
  • Inscrit : 27 Novembre 2004
  Lien vers ce message 07 Décembre 2004, 22:27
[php]<?php
<html>
<?
$variable='1';
?>
</html>
?>[/php]

ca donnerait ca si l'utilisateur mettait
<html>
<?
$variable='1';
?>
</html>

entre les balises php ?? ..
x)


bthivent
Téléchargez Greyline theme V2
 
Chef du projet FSB
Avatar de Genova
  • Age : 26 ans
  • Messages : 14944
  • Inscrit : 16 Septembre 2004
  Lien vers ce message 07 Décembre 2004, 22:47
En effet pas top :s


Cause Im as free as a bird now, And this bird you can not change. - Freebird - Lynyrd Skynyrd
There's someone in my head but it's not me. - Brain damage - Pink Floyd
I said baby, you know Im gonna leave you. - Babe I'm gonna leave you - Led Zeppelin
Father ? yes son, I want to kill you - The end - The Doors
 
Flamme ardente
Avatar de christophe83
  • Messages : 284
  • Inscrit : 16 Septembre 2004
  Lien vers ce message 08 Décembre 2004, 12:09
Un truc appréciable (bien que ce soit un détail)
[php]<?php ?>[/php], faudrait mettre php en majuscule juste après Code.


Retrouvez-moi sur phpBB Francehttp://www.phpbbfrance.com/images/phpbb_5.gif
 
Nouvelle étincelle
Avatar de Dr DLP
  • Messages : 10
  • Inscrit : 22 Décembre 2004
  Lien vers ce message 28 Décembre 2004, 15:55
J'avais fait (fait est très exagéré, c'est entièrement pompé sur le mod bbcode php de Fubonis) un truc du genre pour un système de commentaires :
function color($text)
{
	$matches = array();
	$match_count = preg_match_all("#\[php\](.*?)\[/php\]#si", $text, $matches);
	for ( $i = 0; $i < $match_count; $i ++)
	{
		$before_replace = $matches[1][$i];
		$after_replace = trim($matches[1][$i]);
		$str_to_match = "[php]" . $before_replace . "[/php]";
		$after_replace = str_replace('&lt;', '<', $after_replace);
		$after_replace = str_replace('&gt;', '>', $after_replace);
		$after_replace = str_replace('&amp;', '&', $after_replace);
		$added = FALSE;
		if (preg_match('/^<\?.*?\?>$/si', $after_replace) <= 0)
		{
			$after_replace = "<?php $after_replace ?>";
			$added = TRUE;
		}
		if(strcmp('4.2.0', phpversion()) > 0)
		{
			ob_start();
			highlight_string($after_replace);
			$after_replace = ob_get_contents();
			ob_end_clean();
		}
		else
		{
			$after_replace = highlight_string($after_replace, TRUE);
		}
		if ($added == TRUE)
		{
			$after_replace = str_replace('<font color="#0000BB">&lt;?php ', '<font color="#0000BB">', $after_replace);
			$after_replace = str_replace('<font color="#0000BB">?&gt;</font>', '', $after_replace);
		}
		$after_replace = preg_replace('/<font color="(.*?)">/si', '<span style="color: \\1;">', $after_replace);
		$after_replace = str_replace('</font>', '</span>', $after_replace);
		$after_replace = str_replace("\n", '', $after_replace);
		$replacement .= $after_replace;

		$text = str_replace($str_to_match, $replacement, $text);
	}

	$new_match_count = preg_match_all("#\[blockquote\](.*?)\[/blockquote\]#si", $text, $new_matches);
	for ( $i = 0; $i < $new_match_count; $i ++)
	{
		$ligne = explode("\n",$new_matches[1][$i]);
		reset($ligne);
		while($l = each($ligne)) 
		{
			ereg('^ *',$l[1],$tab);
			$temp_text[$i] .= ereg_replace(' ','&nbsp',$tab[0]);
			$temp_text[$i] .= htmlentities(ereg_replace('^ *','',$l[1]));
			$temp_text[$i] .= "<BR>";
		}
		$oc_to_replace[$i] = "[blockquote]".$new_matches[1][$i]."[/blockquote]";
		$text = str_replace($oc_to_replace[$i],$temp_text[$i],$text);
	}
	return $text;
}

Utilisé avec le traitement suivant :
	$comment = "[blockquote]".$comment."[/blockquote]";
	$comment = str_replace('<?php','[/blockquote][php]',$comment);
	$comment = str_replace('?>','[/php]fin_du_php_125485734[blockquote]',$comment);
	$comment = str_replace('<?','[/blockquote][php]',$comment);
	$comment = color(stripslashes($comment));
	$comment = str_replace('fin_du_php_125485734','&nbsp<font color="#0000BB">?></font>',$comment);

C'est vraiment moche mais fonctionnel.

PS : Les balises php ici ont un souci avec les imbrications d'autres balises php, il faut neutraliser les balises contenues comme avec le bbcode code :)


Elevage virtuel
 
Chef du projet FSB
Avatar de Genova
  • Age : 26 ans
  • Messages : 14944
  • Inscrit : 16 Septembre 2004
  Lien vers ce message 28 Décembre 2004, 15:59
Ok merci de l'info :)


Cause Im as free as a bird now, And this bird you can not change. - Freebird - Lynyrd Skynyrd
There's someone in my head but it's not me. - Brain damage - Pink Floyd
I said baby, you know Im gonna leave you. - Babe I'm gonna leave you - Led Zeppelin
Father ? yes son, I want to kill you - The end - The Doors
 
Répondre


.