国产av日韩一区二区三区精品,成人性爱视频在线观看,国产,欧美,日韩,一区,www.成色av久久成人,2222eeee成人天堂

php實(shí)現(xiàn)簡(jiǎn)單的語(yǔ)法高亮函數(shù)

大家講道理
發(fā)布: 2016-11-11 09:50:34
原創(chuàng)
2277人瀏覽過(guò)

一個(gè)php實(shí)現(xiàn)的簡(jiǎn)單語(yǔ)法高亮顯示的函數(shù),注意:這個(gè)函數(shù)設(shè)計(jì)的比較簡(jiǎn)單,可能對(duì)某些語(yǔ)法不能高亮顯示,你可以自己擴(kuò)充該函數(shù)的功能.

function syntax_highlight($code){
   
    // this matches --> "foobar" <--
    $code = preg_replace(
        '/"(.*?)"/U',
        '"<span style="color: #007F00">$1</span>"', $code
    );
   
    // hightlight functions and other structures like --> function foobar() <---
    $code = preg_replace(
        '/(\s)\b(.*?)((\b|\s)\()/U',
        '$1<span style="color: #0000ff">$2</span>$3',
        $code
    );
   
    // Match comments (like /* */):
    $code = preg_replace(
        '/(\/\/)(.+)\s/',
        '<span style="color: #660066; background-color: #FFFCB1;"><i>$0</i></span>',
        $code
    );
   
    $code = preg_replace(
        '/(\/\*.*?\*\/)/s',
        '<span style="color: #660066; background-color: #FFFCB1;"><i>$0</i></span>',
        $code
    );
   
    // hightlight braces:
    $code = preg_replace('/(\(|\[|\{|\}|\]|\)|\->)/', '<strong>$1</strong>', $code);
   
    // hightlight variables $foobar
    $code = preg_replace(
        '/(\$[a-zA-Z0-9_]+)/', '<span style="color: #0000B3">$1</span>', $code
    );
   
    /* The \b in the pattern indicates a word boundary, so only the distinct
    ** word "web" is matched, and not a word partial like "webbing" or "cobweb"
    */
   
    // special words and functions
    $code = preg_replace(
        '/\b(print|echo|new|function)\b/',
        '<span style="color: #7F007F">$1</span>', $code
    );
   
    return $code;
}
   
   
/*example-start*/
   
/*
** Create some example PHP code:
*/
   
$example_php_code = '
// some code comment:
$example = "foobar";
   
print $_SERVER["REMOTE_ADDR"];
   
$array = array(1, 2, 3, 4, 5);
   
function example_function($str) {
    // reverse string
    echo strrev($obj);
}
   
print example_function("foo");
   
/*
** A multiple line comment
*/
   
print "Something: " . $example;';
   
   
// output the formatted code:
print '<pre class="brush:php;toolbar:false">';
print syntax_highlight($example_php_code);
print '
登錄后復(fù)制
'; ??? /*example-end*/
PHP速學(xué)教程(入門到精通)
PHP速學(xué)教程(入門到精通)

PHP怎么學(xué)習(xí)?PHP怎么入門?PHP在哪學(xué)?PHP怎么學(xué)才快?不用擔(dān)心,這里為大家提供了PHP速學(xué)教程(入門到精通),有需要的小伙伴保存下載就能學(xué)習(xí)啦!

下載
來(lái)源:php中文網(wǎng)
本文內(nèi)容由網(wǎng)友自發(fā)貢獻(xiàn),版權(quán)歸原作者所有,本站不承擔(dān)相應(yīng)法律責(zé)任。如您發(fā)現(xiàn)有涉嫌抄襲侵權(quán)的內(nèi)容,請(qǐng)聯(lián)系admin@php.cn
作者最新文章
最新問(wèn)題
開(kāi)源免費(fèi)商場(chǎng)系統(tǒng)廣告
最新下載
更多>
網(wǎng)站特效
網(wǎng)站源碼
網(wǎng)站素材
前端模板
關(guān)于我們 免責(zé)申明 意見(jiàn)反饋 講師合作 廣告合作 最新更新
php中文網(wǎng):公益在線php培訓(xùn),幫助PHP學(xué)習(xí)者快速成長(zhǎng)!
關(guān)注服務(wù)號(hào) 技術(shù)交流群
PHP中文網(wǎng)訂閱號(hào)
每天精選資源文章推送
PHP中文網(wǎng)APP
隨時(shí)隨地碎片化學(xué)習(xí)
PHP中文網(wǎng)抖音號(hào)
發(fā)現(xiàn)有趣的

Copyright 2014-2025 http://m.miracleart.cn/ All Rights Reserved | php.cn | 湘ICP備2023035733號(hào)