开发者

How can I highlight many code blocks [code][/code] with PHP?

Hello I have a dynamic text and I want to add code like all the forums like this: [code]My code here...[/code]

Is there an easy way to have a function i开发者_如何学Pythonn PHP to do this stuff?? For example if I write on my text:

Hello world example with PHP [code]echo "hello "world";[/code] and an addition example with PHP [code] echo 5+5; //The result will be 10[/code] etc...

Will apear:

Hello world example with PHP

<?php echo "hello "world"; ?>

and an addition example with PHP

<?php echo 5+5; //The result will be 10 ?>

etc....


In addition, you can use this PHP syntax-highlighting library. Geshi


Simple case scenario (no nesting, other weird formatting):

$text = preg_replace('#\[code\](.*?)\[\/code\]#s', '<div class="whatever">$1</div>', $text);
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜