当前位置: 首页>>代码示例>>PHP>>正文


PHP highlight_string函数代码示例

本文整理汇总了PHP中highlight_string函数的典型用法代码示例。如果您正苦于以下问题:PHP highlight_string函数的具体用法?PHP highlight_string怎么用?PHP highlight_string使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了highlight_string函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: getFileSource

 private function getFileSource($file, $offset)
 {
     $fp = fopen($file, 'r');
     $html = '';
     $lines[] = '';
     do {
         $buffer = fgets($fp, 4096);
         $lines[] = $buffer;
     } while (!feof($fp));
     fclose($fp);
     $start = $offset - $this->srcLines;
     if ($start < 0) {
         $start = 0;
     }
     $lines = array_slice($lines, $start, $this->srcLines * 2 + 1, true);
     $a = array_keys($lines);
     $b = sizeOf($a);
     for ($c = 0; $c < $b; ++$c) {
         $line =& $lines[$a[$c]];
         //$line = preg_replace('/^\s/s', '&nbsp;', preg_replace('/\s\s/s', '&nbsp;&nbsp;', htmlspecialchars($line)));
         $html .= '<li class="line';
         if ($a[$c] == $offset) {
             $html .= ' hl';
         }
         $html .= '"><div class="num">' . $a[$c] . '.</div><div class="code"><div class="border">' . $this->convertPHPHighlighting(str_replace('<br />', '', str_replace('?&gt;', '', str_replace('&lt;?php', '', highlight_string('<?php ' . $line . ' ?>', true))))) . '</div></div></li>';
     }
     return $html;
 }
开发者ID:kurtschwarz,项目名称:FFFUU-Exception,代码行数:28,代码来源:Exception.php

示例2: printCode

function printCode($code, $high_light = 0, $lines_number = 0, $line_number_start = 0)
{
    if (!is_array($code)) {
        $code = explode("\n", $code);
    }
    $count_lines = count($code);
    $r = "";
    $line = $line_number_start;
    foreach ($code as $code_line) {
        if ($lines_number) {
            $r1 = "<span class=\"lines_number\">" . $line . ". </span>";
        }
        if ($high_light) {
            if (ereg("<\\?(php)?[^[:graph:]]", $code_line)) {
                $r2 = highlight_string($code_line, 1);
            } else {
                $r2 = ereg_replace("(&lt;\\?php&nbsp;)+", "", highlight_string("<?php " . $code_line, 1));
            }
        } else {
            $r2 = !$line ? "<pre>" : "";
            $r2 .= htmlentities($code_line);
            $r2 .= $line == $count_lines - 1 ? "<br /></pre>" : "";
        }
        $r .= $r1 . $r2;
        $line++;
    }
    return "<div class=\"code\">" . $r . "</div>";
}
开发者ID:BackupTheBerlios,项目名称:banbury-svn,代码行数:28,代码来源:PrintCode.php

示例3: getMessages

function getMessages($user, $reverse, $last)
{
    // get messages
    $time = date("F d Y H:i:s.", filemtime("msg/" . $user));
    $time = prettyDate($time) . ".";
    if ($time == "46 years ago.") {
        $time = "Never ago.";
    }
    $curtime = date("F d Y H:i:s.", time());
    if (!isset($last)) {
        echo "Message last receieved: " . $time . " Current time: " . $curtime . "<br>\n";
    }
    echo "Messages, sorted by recent:<br>\n";
    if (!$reverse) {
        $messages = file("msg/" . $user);
    } else {
        $messages = array_reverse(file("msg/" . $user));
    }
    echo "<div class='scrolls'>";
    foreach ($messages as $message) {
        highlight_string($message) . "<br>";
    }
    echo "</div>";
    if (isset($_POST["api"])) {
        die;
    }
}
开发者ID:pielover88888,项目名称:account,代码行数:27,代码来源:index.php

示例4: code

 /**
  * Preview code from a string containing PHP code
  *
  * @param string   $code       php code
  * @param int|null $activeLine active line number
  * @param int|null $lineRange  range of lines to render (around active line)
  * @param string   $className  wrapper class name
  * @return string|null
  */
 public static function code($code, $activeLine = null, $lineRange = null, $className = 'code-preview')
 {
     $code = @highlight_string($code, true);
     if (false !== $code) {
         return self::render($code, $activeLine, $lineRange, $className);
     }
 }
开发者ID:kuria,项目名称:error,代码行数:16,代码来源:PhpCodePreview.php

示例5: processor_enscript

function processor_enscript($formatter, $value)
{
    global $DBInfo;
    $enscript = 'enscript ';
    ##enscript --help-pretty-print |grep "^Name" |cut -d" " -f 2
    $syntax = array("ada", "asm", "awk", "c", "changelog", "cpp", "diff", "diffu", "delphi", "elisp", "fortran", "haskell", "html", "idl", "java", "javascript", "mail", "makefile", "nroff", "objc", "pascal", "perl", "postscript", "python", "scheme", "sh", "sql", "states", "synopsys", "tcl", "verilog", "vhdl", "vba", "php");
    $options = array("number");
    $vartmp_dir =& $DBInfo->vartmp_dir;
    $line = '';
    if ($value[0] == '#' and $value[1] == '!') {
        list($line, $value) = explode("\n", $value, 2);
    }
    # get parameters
    if ($line) {
        $line = substr($line, 2);
        $tag = strtok($line, ' ');
        $type = strtok(' ');
        $extra = strtok('');
        if ($tag != 'enscript') {
            $extra = $type;
            $type = $tag;
        }
    }
    $option = '';
    if ($extra == "number") {
        $option = '-C ';
    }
    $src = $value;
    if (!in_array($type, $syntax)) {
        return "<pre class='code'>\n{$line}\n{$src}\n</pre>\n";
    }
    if ($type == 'php') {
        ob_start();
        highlight_string($src);
        $html = ob_get_contents();
        ob_end_clean();
    } else {
        $tmpf = tempnam($vartmp_dir, "FOO");
        $fp = fopen($tmpf, "w");
        fwrite($fp, $src);
        fclose($fp);
        #-E%s -W html -J "" -B --color --word-wrap
        #$cmd="ENSCRIPT_LIBRARY=/home/httpd/wiki/lib $enscript -q -o - -E$type -W html --color --word-wrap ".$tmpf;
        if (!empty($DBInfo->enscript_style)) {
            $cmd = "{$enscript} -q -o - {$option} -E{$type} --language=html {$DBInfo->enscript_style} --color --word-wrap " . $tmpf;
        } else {
            $cmd = "{$enscript} -q -o - {$option} -E{$type} --language=html --style=ifh --color --word-wrap " . $tmpf;
        }
        $fp = popen($cmd . $formatter->NULL, 'r');
        $html = '';
        while ($s = fgets($fp, 1024)) {
            $html .= $s;
        }
        pclose($fp);
        $html = eregi_replace('^.*<pre>', '<div class="wikiPre"><pre class="wiki">', $html);
        $html = eregi_replace('<\\/PRE>.*$', '</pre></div>', $html);
        unlink($tmpf);
    }
    return $html;
}
开发者ID:ahastudio,项目名称:moniwiki,代码行数:60,代码来源:enscript.php

示例6: highlight

 public function highlight($string)
 {
     $string = highlight_string("<?php " . $string, true);
     $find = array('<span style="color: #0000BB">&lt;?php&nbsp;</span>', '&lt;?php&nbsp;');
     $string = str_replace($find, '', $string);
     return $string;
 }
开发者ID:andrewyang96,项目名称:phpmongodb,代码行数:7,代码来源:Cryptography.php

示例7: dump

function dump()
{
    // Search the function caller
    $backtrace = debug_backtrace();
    $trace = current($backtrace);
    // If parent function is debug, shift
    if (empty($trace['file']) && @$backtrace[1]['function'] == 'call_user_func_array') {
        next($backtrace);
        // Skip call_user_func_array
        $trace = next($backtrace);
    }
    // Cut root dir from file path
    $root = str_replace('\\', '/', defined('ROOT_DIR') ? ROOT_DIR : $_SERVER['DOCUMENT_ROOT']);
    $file = str_replace('\\', '/', $trace['file']);
    $file = preg_replace('/^' . preg_quote($root, '/') . '/', '', $file);
    // Environment detection
    $http = PHP_SAPI != 'cli' && !(defined('DEBUG_OUTPUT') && DEBUG_OUTPUT == 'text');
    $dump = $http ? 'var_dump' : 'print_r';
    $args = ($a = func_get_args()) ? $a : array("checkpoint!");
    // Output file path
    echo $http ? "<!-- don't be evil --><code style='color: green'><b>" . $file . "</b> on line <b>" . @$trace['line'] . "</b></code><br /><br />" : "{$file} on line {$trace['line']}\n";
    // Output variables
    foreach ($args as $cur) {
        ob_start();
        $dump($cur);
        $cur = ob_get_contents();
        ob_end_clean();
        if (!extension_loaded('xdebug') && $http) {
            $cur = highlight_string("<?php\n\n{$cur}\n?>", true);
        }
        echo $cur;
    }
    echo $http ? "<hr><br />" : "\n" . str_repeat('-', 70) . "\n\n";
}
开发者ID:sergeytkachenko,项目名称:angular-gulp-phalcon,代码行数:34,代码来源:debug.php

示例8: render

 public function render(&$____code, $____local_assigns, $____file_path)
 {
     $this->_options['variables'] = $____local_assigns;
     $this->_options['code'] =& $____code;
     $this->_options['functions'] = array('');
     $this->_options['file_path'] = $____file_path;
     if ($this->_templateNeedsCompilation()) {
         $TemplateEngine = $this->_getTemplateEngineInstance($this->_templateEngine);
         $TemplateEngine->init(array('code' => $____code, 'helper_loader' => $this->_AkActionView->getHelperLoader()));
         $____code = $TemplateEngine->toPhp();
         if ($____code === false) {
             if (AK_PRODUCTION_MODE) {
                 trigger_error(join("\n", $TemplateEngine->getErrors()), E_USER_ERROR);
                 return false;
             } else {
                 trigger_error("Could not compile " . $this->_options['file_path'] . "\n\n" . join("\n", $TemplateEngine->getErrors()), E_USER_ERROR);
                 echo highlight_string($TemplateEngine->getParsedCode(), true);
                 die;
             }
         }
         if (AK_TEMPLATE_SECURITY_CHECK && $this->_templateNeedsValidation()) {
             if (!$this->_assertForValidTemplate()) {
                 return false;
             }
         }
         $this->_saveCompiledTemplate();
     }
     (array) $____local_assigns;
     extract($____local_assigns, EXTR_SKIP);
     ob_start();
     include $this->_getCompiledTemplatePath();
     empty($shared) || $this->_AkActionView->addSharedAttributes($shared);
     return ob_get_clean();
 }
开发者ID:bermi,项目名称:akelos,代码行数:34,代码来源:php_template_handler.php

示例9: highlight

 public function highlight($data)
 {
     $src = highlight_string($data, true);
     $src = str_replace("\n", '', $src);
     $src = preg_replace('/<br[^>]*>/', PHP_EOL, $src);
     $src = preg_replace_callback('/<span style="color: #([0-F]+)">/', function ($m) {
         switch ($m[1]) {
             case '0000BB':
                 // Idents
                 return "[34;1m";
             case 'FF8000':
                 // Comments
                 return "[30m";
             case '007700':
                 // Symbols
                 return "[37;1m";
             case 'DD0000':
                 // Strings
                 return "[32;1m";
             default:
                 return "[0m";
         }
     }, $src);
     // Ensure no tags are left
     $src = preg_replace('/<[^>]+>/', '', $src);
     $src = str_replace('&nbsp;', ' ', $src);
     $src = html_entity_decode($src);
     $src = $src . "[0m";
     return $src;
 }
开发者ID:rafeca,项目名称:Spec-PHP,代码行数:30,代码来源:Dump.php

示例10: showMethod

    public static function showMethod($class, $methods)
    {
        $rclass     = new ReflectionClass($class);
        $definition = implode("", array_slice(file($rclass->getFileName()), $rclass->getStartLine()-1, 1));

        $code       = "\n".$definition."\n....\n\n";

        if (!is_array($methods))
            $methods = array($methods);

        foreach ($methods as $method) {
            $method     = new ReflectionMethod($class, $method);
            $filename   = $method->getFileName();
            $start_line = $method->getStartLine()-1;
            $end_line   = $method->getEndLine();
            $length     = $end_line - $start_line;
            $source     = file($filename);
            $content    = implode("", array_slice($source, $start_line, $length));

            $code .= $content."\n\n";
        }

        $code = highlight_string("<?php ".$code, true);
        $code = str_replace('&lt;?php&nbsp;', '', $code);

        return "<pre>\n" . $code . "\n</pre>";
    }
开发者ID:simplylouis,项目名称:online_book_shop_20151110_laravel_5,代码行数:27,代码来源:Documenter.php

示例11: highlight

 /**
  * @see	\wcf\system\bbcode\highlighter\Highlighter::highlight()
  */
 public function highlight($code)
 {
     // add starting php tag
     $phpTagsAdded = false;
     if (mb_strpos($code, '<?') === false) {
         $phpTagsAdded = true;
         $code = '<?php ' . $code . ' ?>';
     }
     // do highlight
     $highlightedCode = highlight_string($code, true);
     // clear code
     $highlightedCode = str_replace('<code>', '', $highlightedCode);
     $highlightedCode = str_replace('</code>', '', $highlightedCode);
     // remove added php tags
     if ($phpTagsAdded) {
         $regex = new Regex('([^\\2]*)(&lt;\\?php&nbsp;)(.*)(&nbsp;.*\\?&gt;)([^\\4]*)', Regex::CASE_INSENSITIVE | Regex::DOT_ALL);
         $highlightedCode = $regex->replace($highlightedCode, '\\1\\3\\5');
     }
     // remove breaks
     $highlightedCode = str_replace("\n", "", $highlightedCode);
     $highlightedCode = str_replace('<br />', "\n", $highlightedCode);
     // get tabs back
     $highlightedCode = str_replace('&nbsp;&nbsp;&nbsp;&nbsp;', "\t", $highlightedCode);
     // replace non breaking space with normal space, white-space is preserved by CSS
     $highlightedCode = str_replace('&nbsp;', " ", $highlightedCode);
     // convert colors to classes
     $highlightedCode = strtr($highlightedCode, self::$colorToClass);
     // replace double quotes by entity
     return Regex::compile('(?<!\\<span class=)"(?!\\>)')->replace($highlightedCode, '&quot;');
 }
开发者ID:Gwenwhyfer,项目名称:WCF,代码行数:33,代码来源:PhpHighlighter.class.php

示例12: php

 /**
  * apply PHP highlight_string
  *
  * @param string $text source string
  *
  * @return string
  */
 public function php($text)
 {
     $text = trim($text);
     $addedOpenTag = false;
     if (!strpos($text, "<?php") && substr($text, 0, 5) !== "<?php") {
         $text = "<?php " . $text;
         $addedOpenTag = true;
     }
     $oldlevel = error_reporting(0);
     //There is a bug in the highlight function(php < 5.3) that it doesn't render
     //backslashes properly like in \s. So here we replace any backslashes
     $text = str_replace("\\", "XxxX", $text);
     $buffer = highlight_string($text, true);
     // Require PHP 4.20+
     //Placing backspaces back again
     $buffer = str_replace("XxxX", "\\", $buffer);
     error_reporting($oldlevel);
     $pos_open = $pos_close = 0;
     if ($addedOpenTag) {
         $pos_open = strpos($buffer, '&lt;?php&nbsp;');
     }
     $str_open = $addedOpenTag ? substr($buffer, 0, $pos_open) : "";
     $length_open = $addedOpenTag ? $pos_open + 14 : 0;
     $str_internal = substr($buffer, $length_open);
     $buffer = $str_open . $str_internal;
     return $buffer;
 }
开发者ID:ming-hai,项目名称:XoopsCore,代码行数:34,代码来源:SyntaxHighlight.php

示例13: highLight

 public function highLight(string $str, array $settings = []) : string
 {
     $phpFamily = !empty($settings['php:family']) ? 'font-family:' . $settings['php:family'] : 'font-family:Consolas';
     $phpSize = !empty($settings['php:size']) ? 'font-size:' . $settings['php:size'] : 'font-size:12px';
     $phpStyle = !empty($settings['php:style']) ? $settings['php:style'] : '';
     $htmlFamily = !empty($settings['html:family']) ? 'font-family:' . $settings['html:family'] : '';
     $htmlSize = !empty($settings['html:size']) ? 'font-size:' . $settings['html:size'] : '';
     $htmlColor = !empty($settings['html:color']) ? $settings['html:color'] : '';
     $htmlStyle = !empty($settings['html:style']) ? $settings['html:style'] : '';
     $comment = !empty($settings['comment:color']) ? $settings['comment:color'] : '#969896';
     $commentStyle = !empty($settings['comment:style']) ? $settings['comment:style'] : '';
     $default = !empty($settings['default:color']) ? $settings['default:color'] : '#000000';
     $defaultStyle = !empty($settings['default:style']) ? $settings['default:style'] : '';
     $keyword = !empty($settings['keyword:color']) ? $settings['keyword:color'] : '#a71d5d';
     $keywordStyle = !empty($settings['keyword:style']) ? $settings['keyword:style'] : '';
     $string = !empty($settings['string:color']) ? $settings['string:color'] : '#183691';
     $stringStyle = !empty($settings['string:style']) ? $settings['string:style'] : '';
     $background = !empty($settings['background']) ? $settings['background'] : '';
     $tags = isset($settings['tags']) ? $settings['tags'] : true;
     ini_set("highlight.comment", "{$comment}; {$phpFamily}; {$phpSize}; {$phpStyle}; {$commentStyle}");
     ini_set("highlight.default", "{$default}; {$phpFamily}; {$phpSize}; {$phpStyle}; {$defaultStyle}");
     ini_set("highlight.keyword", "{$keyword}; {$phpFamily}; {$phpSize}; {$phpStyle}; {$keywordStyle} ");
     ini_set("highlight.string", "{$string};  {$phpFamily}; {$phpSize}; {$phpStyle}; {$stringStyle}");
     ini_set("highlight.html", "{$htmlColor}; {$htmlFamily}; {$htmlSize}; {$htmlStyle}");
     // ----------------------------------------------------------------------------------------------
     // HIGHLIGHT
     // ----------------------------------------------------------------------------------------------
     $string = highlight_string($str, true);
     // ----------------------------------------------------------------------------------------------
     $string = Security::scriptTagEncode(Security::phpTagEncode(Security::htmlDecode($string)));
     $tagArray = $tags === true ? ['<div style="' . $background . '">&#60;&#63;php', '&#63;&#62;</div>'] : ['<div style="' . $background . '">', '</div>'];
     return str_replace(['&#60;&#63;php', '&#63;&#62;'], $tagArray, $string);
 }
开发者ID:znframework,项目名称:znframework,代码行数:33,代码来源:Text.php

示例14: render

function render($markdown)
{
    /* Code blocks */
    $markdown = preg_replace("/^```php\n([^`]+)```/m", highlight_string("\$1"), $markdown);
    /* Titles */
    $markdown = preg_replace("/^\\#\\s+(.*)\$/m", "<h1>\$1</h1>", $markdown);
    $markdown = preg_replace("/^\\##\\s+(.*)\$/m", "<h2>\$1</h2>", $markdown);
    $markdown = preg_replace("/^\\###\\s+(.*)\$/m", "<h3>\$1</h3>", $markdown);
    $markdown = preg_replace("/^\\####\\s+(.*)\$/m", "<h4>\$1</h4>", $markdown);
    $markdown = preg_replace("/^\\#####\\s+(.*)\$/m", "<h5>\$1</h5>", $markdown);
    $markdown = preg_replace("/^\\######\\s+(.*)\$/m", "<h6>\$1</h6>", $markdown);
    /* Inline statements */
    $markdown = preg_replace("/`([^`]+)`/m", "<code>\$1</code>", $markdown);
    $markdown = preg_replace("/\\*\\*([^**]+)\\*\\*/m", "<strong>\$1</strong>", $markdown);
    $markdown = preg_replace("/\\*([^*]+)\\*/m", "<em>\$1</em>", $markdown);
    $markdown = preg_replace("/~~([^~]+)~~/m", "<s>\$1</s>", $markdown);
    /* Links */
    $markdown = preg_replace("/\\[([^\\]]+)\\]\\(([^)]+)\\)/m", "<a href=\"\$2\">\$1</a>", $markdown);
    /* Line breaks */
    $markdown = preg_replace("/[ ]{2,2}\n/", "<br>\n", $markdown);
    /* Paragraphs */
    $paragraphs = explode("\n\n", $markdown);
    $markdown = "";
    foreach ($paragraphs as $p) {
        $p = trim($p);
        if (preg_match("/^</", $p)) {
            $markdown .= $p . "\n";
        } else {
            $markdown .= "<p>{$p}</p>\n";
        }
    }
    return $markdown;
}
开发者ID:mbruton,项目名称:markdown,代码行数:33,代码来源:test.php

示例15: viewBlockAction

 public function viewBlockAction()
 {
     $blockClass = $this->getRequest()->get('block');
     $absoluteFilepath = Mage::helper('debug')->getBlockFilename($blockClass);
     $source = highlight_string(file_get_contents($absoluteFilepath), true);
     echo $this->_debugPanel("Block Source: <code>{$blockClass}</code>", '' . $source . '');
 }
开发者ID:xiaoguizhidao,项目名称:blingjewelry-prod,代码行数:7,代码来源:IndexController.php


注:本文中的highlight_string函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。