https://www.icyphoenix.com/viewtopic.php?f=28&t=4740 ----------------------------------- glenflet Sat 20 Sep, 2008 03:36 PHP Based Code To HTML With BBcode ----------------------------------- ]I wrote this PHP script to convert JAVA, PYTHON, VISUAL BASIC, and VISUAL BASIC .NET to formated html, using a style sheet. i.e. [code linenumbers=true]// Sample Class provide to demostrate how to create Abritute methods in Java public class Sample1 { // internal variables private int age; // Asscesor or Get Method public int getAge() { return age; } // Mutator or Set Method public void setAge(int value) { age = value; } }[/code] is converted to [code linenumbers=true]// Sample Class provide to demostrate how to create Abritute methods in Java
public class Sample1
{
// internal variables
private int age;
// Asscesor or Get Method
public int getAge()
{
return age;
}
// Mutator or Set Method
public void setAge(int value)
{
age = value;
}
}
[/code] see this page for the output to user http://learntoprogram.net84.net/index.php?page=abritute&lang=java I want to adapt this script so that it works with both, IcyPhoenix and phpBB3 BBcode for the [Code] tag. Can someone give me some help with this, Thank you. Also feel free to use this code your self, under the trems of either the CDDL or GPL Also the code takes both a string for the code input or a filename that points to a source file, it also takes a language ID. ----------------------------------- Lopalong Sat 20 Sep, 2008 08:36 Re: PHP Based Code To HTML With BBcode ----------------------------------- Moved to "Other Mods Support" - - - ----------------------------------- glenflet Tue 23 Sep, 2008 08:09 Re: PHP Based Code To HTML With BBcode ----------------------------------- I worked out how to do this with pbpBB3 BBcode, but I'm not sure how to do it with Icy Phoenix, can some one help m [hr] EDIT: Tue 23 Sep, 2008 23:39 I found out My so called succes was not what it seams, the varable passing didn't work proply, it only worked because my test language was the defualt language. So i need halp with passing, singal variable to phpBB3 BBcode, I aslo need to known how if possible to pass mulitable variables in phpBB3. ----------------------------------- Mighty Gorgon Thu 25 Sep, 2008 10:02 Re: PHP Based Code To HTML With BBcode ----------------------------------- Hi, to be able to use these scripts within Icy Phoenix you need to alter bbcode.php and add highlighting there. You can refer to CODE part in that file and apply what you need. Regarding phpBB 3... I don't know. ----------------------------------- Lopalong Thu 25 Sep, 2008 11:41 Re: PHP Based Code To HTML With BBcode ----------------------------------- It may also be helpful if you add your attachments in .zip format only - Not everyone uses exotic compression. ;) ----------------------------------- glenflet Fri 26 Sep, 2008 04:18 Re: PHP Based Code To HTML With BBcode ----------------------------------- I Include the followign file in the BBcode.php [code linenumbers=false syntax=php]", $lines); switch ($lang) { case "JAVA": $lines = java2html($lines); break; case "PYTHON": $lines = python2html($lines); break; case "VB": $lines = vb2html($lines); break; case "VB.NET": $lines = vb_net2html($lines); break; default: // Assume Java, if fail $lines = java2html($lines); break; } return $lines; } ?>[/code] I put the following in the syntax = php if statment [code linenumbers=false] else { $text = code2html($text,strtoupper($item['params']['syntax'])); }[/code] However when I tested it with lang = python, I get a blank code box, wwhy would this happen I got the following HTML Output [code linenumbers=false]div class="code">
Code: [Hide]
    [/code] from [code linenumbers=false][code linenumbers=true syntax=python]def Hello(): return "Hello World"[/code][/code] ----------------------------------- Mighty Gorgon Fri 26 Sep, 2008 13:16 Re: PHP Based Code To HTML With BBcode ----------------------------------- Try to add your code here: [codeblock] $php_syntax = false; if(isset($item['params']['syntax'])) { if ($item['params']['syntax'] == 'php') { $html = strtr($text, array_flip(get_html_translation_table(HTML_ENTITIES))); $html = highlight_string($html, true); $html_search = array('', '', '', ' '); $xhtml_replace = array('', '', '', ' ', '> <'); $xhtml_replace = array('n", " n
  1. ",$html); $html = "
  2. " . $html; }[/codeblock] FIND [codeblock] if ($item['params']['syntax'] == 'php') { $html = strtr($text, array_flip(get_html_translation_table(HTML_ENTITIES))); $html = highlight_string($html, true); $html_search = array('', '', '', ' '); $xhtml_replace = array('', '', 'n", " 
    3. n
  3. ",$html); [/spoiler] Let me know, Thank you, xmenfile ----------------------------------- glenflet Mon 29 Sep, 2008 03:07 Re: PHP Based Code To HTML With BBcode ----------------------------------- Sorry that was a small error on my part I losted the escape charaters when I copyied the code into the post. change [code linenumbers=false]$html = ereg_replace("
    n", " 
    4. n
  4. ",$html);[/code] to [code linenumbers=false]$html = ereg_replace("
    n", " 
    5. n
  5. ",$html);[/code] also change your next line to the following it will be incorret as well [code linenumbers=false]$html = "
  6. " . $html;[/code] ----------------------------------- glenflet Mon 06 Oct, 2008 10:18 Re: PHP Based Code To HTML With BBcode ----------------------------------- I've Recently Made Several improvements to PHP Code 2 Html, so if your useing it you may want to update to this version it has no known errors. ----------------------------------- Mighty Gorgon Fri 10 Oct, 2008 13:14 Re: PHP Based Code To HTML With BBcode ----------------------------------- Thanks for sharing, I'm sure CODING dedicated forums will appreciate this. Good job.