scheols Posted August 1, 2006 Share Posted August 1, 2006 can someone show me the php highlihting so you can highlight php scriptspreg_replace() with highlight_string() Quote Link to comment https://forums.phpfreaks.com/topic/16173-php-syntax-highlighter/ Share on other sites More sharing options...
hackerkts Posted August 1, 2006 Share Posted August 1, 2006 If you want to highlight the php scripts, just just do thisfor example:[code]<?phphighlight_string('<?phpecho "Hello world!";?>');?>[/code] Quote Link to comment https://forums.phpfreaks.com/topic/16173-php-syntax-highlighter/#findComment-66859 Share on other sites More sharing options...
scheols Posted August 1, 2006 Author Share Posted August 1, 2006 man i dont feel like doing that im trying 2 do BB codes[code][code=php:0][/code][/code]so yeah im trying to add it so users can do this. Quote Link to comment https://forums.phpfreaks.com/topic/16173-php-syntax-highlighter/#findComment-66869 Share on other sites More sharing options...
wildteen88 Posted August 1, 2006 Share Posted August 1, 2006 I find it easier to use a function called [url=http://uk.php.net/manual/en/function.preg-replace-callback.php]preg_replace_callback[/url] when doing PHP BBCode parsers. Heres a quick demo:[code]<?phpfunction bbcode($txt){ // bbcodes $bbcodes = array( "|\[b\](.+)\[/b\]|is", "|\[u\](.+)\[/u\]|is", "|\[i\](.+)\[/i\]|is" ); // html $replace = array( "<strong>$1</strong>", "<u>$1</u>", "<em>$1</em>" ); $text = preg_replace($bbcodes, $replace, $txt); // call a dedicated function to parse our PHP BBCodes: $text = preg_replace_callback("#\[php\](.*?)\[\/php\]#is", 'doPHP', $text); return nl2br($text);}// our dedicated PHP BBCode functionfunction doPHP($matches){ #echo '<pre>' . print_r($matches, true) . '</pre>'; //highlight PHP Code $php = highlight_string($matches[0], true); // remove the mataches unset($mataches); // remove the php BBCodes $php = preg_replace("#(\[php\]|\[/php\])#i", "", $php); //clean up spaces and extra line breaks $php = str_replace(' ', ' ', $php); $php = str_replace('<br />', '', $php); return $php;}$str = "[code=php:0]<?phpecho 'hello world';if(\$var == 'hello world'){ echo 'true';}?>[/code]";// call the bbcode parser function.$str = bbcode($str);echo $str;?>[/code] Quote Link to comment https://forums.phpfreaks.com/topic/16173-php-syntax-highlighter/#findComment-66921 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.