|
|
|
|
|
для: cheops
(19.03.2005 в 18:36)
| | сенкс | |
|
|
|
|
|
|
|
для: JIEXA
(19.03.2005 в 17:32)
| | Это код следует оформить в виде функции light() и использовать функцию преобразования тэгов, например, из нашего форума LiteForum
<?php
function post_work_up($postbody)
{
// Обрабатываем теги [html], [/html]
$lastocc = 0;
$sndocc = 1;
$result = "";
while($sndocc)
{
$fstocc = strpos($postbody,"[html]",$lastocc);
$sndocc = strpos($postbody,"[/html]",$fstocc);
if(($fstocc>0 && $sndocc>0 && $lastocc>0) || ($fstocc >= 0 && $sndocc>0 && $lastocc == 0))
{
$result .= nl2br(htmlspecialchars(substr($postbody,$lastocc,$fstocc - $lastocc)));
$result .= "<table border=0 ><tr><td class=codeblock>".light(substr($postbody,$fstocc + 6,$sndocc - $fstocc - 6))."</td></tr></table>";
$lastocc = $sndocc + 7;
}
else
{
$result .= nl2br(htmlspecialchars(substr($postbody,$lastocc,strlen($postbody)-$lastocc)));
break;
}
}
return $result;
}
?>
|
Функция принимает единственный параметр с тестом, содержащим тэги [html][/html] и возвращает уже текст, в котором выделенные блоки подсвечены. | |
|
|
|
|
|
|
| Ниже приведённый код, подсвечивает синтаксис хтмл кода. Как сделать, чтобы он подсвечевал только код находящийся в спец тегах [html][/html]
<?php
$txt = str_replace( "<" , "<" , $txt);
$txt = str_replace( ">" , ">" , $txt);
$txt = str_replace( "\"", """, $txt);
$txt = preg_replace( "!<\!--(.+?)(//)?-->!s", "<!<span style='color:red'>--\\1--\\2</span>>", $txt);
$txt = preg_replace( "#<([^&<>]+)>#s", "<<span style='color:blue'>\\1</span>>", $txt);
$txt = preg_replace( "#<([^&<>]+)=#s", "<<span style='color:blue'>\\1</span>=", $txt);
$txt = preg_replace( "#</([^&]+)>#s", "</<span style='color:blue'>\\1</span>>", $txt);
$txt = preg_replace( "!=("|')([^<>])("|')(\s|>)!s", "=\\1<span style='color:purple'>\\2</span>\\3\\4", $txt);
$txt = str_replace( "\n", "<br>", str_replace("\r\n", "\n", $txt));
print "<table border=0 ><tr><td class='code-html'><pre>".$txt."</pre></td></tr></table>";
?>
|
| |
|
|
|
|