السلام عليكم ورحمة الله وبركاته ..
لدي صفحة فيها حقل نص , يتم فيه كتابة كود php , وبعد كتابة هذا الكود يتم تلوينه بواسطة هذه الدلة ...
لكن يوجد مشكلة بسيطه
عندك كتابة
كود PHP:
<? print "XP"; ?>
ومن ثم تمريره عبر الداله highlight_string
يتم إخراجه هكذا :
<? print "XP\"; ?>
قمت بالدخول لموقع php.net بحثاً عن دوال ...
ودجربت عدة دوال , منها :
كود PHP:
<?
// func1function print_php_code($str, $type) {
switch ($type) {
case "text":
$str = highlight_string($str, true);
break;
case "file":
$str = highlight_file($str, true);
break;
}
$str = explode("<br />", $str);
echo "<div>";
echo "<ol>\n";
foreach ($str as $line => $syntax) {
echo "<li><code>" . $syntax . "</code></li>";
}
echo "</ol>\n";
echo "</div>";
}
?>
كود PHP:
<?php // GET sOURCE O THE PGE
// $f = file_get_contents($_SERVER['SCRIPT_FILENAME']);
// highlight_string($f);
// exit();
?>
<?php
function highlight_code($code, $inline=false, $return=false) // Pre php 4 support for capturing highlight
{
(string) $highlight = "";
if ( version_compare(PHP_VERSION, "4.2.0", "<") === 1 )
{
ob_start(); // start output buffering to capture contents of highlight
highlight_string($code);
$highlight = ob_get_contents(); // capture output
ob_end_clean(); // clear buffer cleanly
}
else
{
$highlight=highlight_string($code, true);
}
# Using preg_replace will allow PHP 4 in on the fun
if ( $inline === true )
$highlight=preg_replace("/<code>/i","<code class=\"inline\">",$highlight);
else
$highlight=preg_replace("/<code>/i","<code class=\"block\">",$highlight);
if ( $return === true )
{
return $highlight;
}
else
{
echo $highlight;
}
}
?>
كود PHP:
<?php // special
function highlight_php($string)
{
$Line = explode("\n",$string); for($i=1;$i<=count($Line);$i++)
{
$line .= " ".$i." <br>";
}
ob_start();
highlight_string($string);
$Code=ob_get_contents();
ob_end_clean();
$header='<table border="0" cellpadding="0" cellspacing="0" width="95%" style="border-style: solid; border-width:1px; border-color: white black black white">
<tr>
<td width="100%" colspan="2" style="border-style: solid; border-width:1px; border-color: white; background-color: #99ccff; font-family:Arial; color:white; font-weight:bold;">Php-Code:</td>
</tr>
<tr>
<td width="3%" valign="top" style="background-color: #99ccff; border-style: solid; border-width:1px; border-color: white;"><code>'.$line.'</code></td>
<td width="97%" valign="top" style="background-color: white;"><div style="white-space: nowrap; overflow: auto;"><code>'; $footer=$Code.'</div></code></td>
</tr>
</table>'; return $header.$footer;
} print highlight_php('<? print "Xp"; ?>');?>
كلها فيها نفس المشكلة :looking:.
أتمنى الرد عاجلاً , وشكراً.