scvinodkumar Posted June 3, 2009 Share Posted June 3, 2009 Hi, Could you please a good free php code snippet library other php-csl. I need the library with database. Quote Link to comment Share on other sites More sharing options...
trq Posted June 3, 2009 Share Posted June 3, 2009 What? Quote Link to comment Share on other sites More sharing options...
scvinodkumar Posted June 3, 2009 Author Share Posted June 3, 2009 Hi, sorry, I have a php code library. I would to like to give color to functions and variable. so, when i posted the code in the form, it would display with code highlight Quote Link to comment Share on other sites More sharing options...
trq Posted June 3, 2009 Share Posted June 3, 2009 Sorry, your still making little to no sense. Quote Link to comment Share on other sites More sharing options...
jsschmitt Posted June 3, 2009 Share Posted June 3, 2009 If i understand it correctly, they are looking for code the has the effect of the "code" tags on the forum. They are creating a repository of PHP code, and want to make it show the syntax correctly... Right? Quote Link to comment Share on other sites More sharing options...
scvinodkumar Posted June 3, 2009 Author Share Posted June 3, 2009 Hi, Yeah you right. Thanks for understanding Quote Link to comment Share on other sites More sharing options...
gevans Posted June 3, 2009 Share Posted June 3, 2009 http://alexgorbatchev.com/wiki/SyntaxHighlighter Quote Link to comment Share on other sites More sharing options...
scvinodkumar Posted June 3, 2009 Author Share Posted June 3, 2009 Hi, i think those are depends on wiki so i can't able to use in my own php code. Quote Link to comment Share on other sites More sharing options...
gevans Posted June 3, 2009 Share Posted June 3, 2009 Care to explain a little further? "depends on wiki"?? "i can't able to use in my own php code"?? Quote Link to comment Share on other sites More sharing options...
Ken2k7 Posted June 3, 2009 Share Posted June 3, 2009 Look at highlight_file and highlight_string. Quote Link to comment Share on other sites More sharing options...
scvinodkumar Posted June 4, 2009 Author Share Posted June 4, 2009 Hi, where can i found code similar to phpfreaks used to display the php code in the forum between code & /code Thanks Quote Link to comment Share on other sites More sharing options...
Ken2k7 Posted June 4, 2009 Share Posted June 4, 2009 Hi, Do you take suggestions when they're given to you? Have you tried any of the suggestions people posted? If not, I don't see why we should give help to you. If you don't want to take my advice and you are very curious about how SMF (the forum software used here on PHPFreaks) does it, then download SMF and view the source code. I never used SMF so I have no idea what file to tell you to look at. The are BB Codes. They're in almost every forum software. You can write a simple parser for that using preg_replace. Thanks! Quote Link to comment Share on other sites More sharing options...
scvinodkumar Posted June 4, 2009 Author Share Posted June 4, 2009 Hi, Yeah, i tested those code given by gevans, but it is not displaying any thing there when i add the php code in the test.html file the code that i added in the html file is <pre class="brush: php;"> <?php if (isset($parameter) && $parameter != "") { if ($parameter == "PUBLIC") { $run_result = true; } else if ($parameter == "LOGGED_IN" && isset($_SESSION['userid']) && $_SESSION['userid'] != "" && $_SESSION['userid'] != -1) { $run_result = true; } } ?> </pre> And the output comes as SyntaxHihglighter Test This is a test file to insure that everything is working well. 1. (empty line) Quote Link to comment Share on other sites More sharing options...
Ken2k7 Posted June 4, 2009 Share Posted June 4, 2009 And what about mine? Quote Link to comment Share on other sites More sharing options...
scvinodkumar Posted June 4, 2009 Author Share Posted June 4, 2009 Hi, I tried with highlight_file() and highlight_string(). It works only with a few lines code. If i added big program then the colors are not reflecting properly. Quote Link to comment Share on other sites More sharing options...
scvinodkumar Posted June 4, 2009 Author Share Posted June 4, 2009 Hi, Again, I tried a function used at php.net with highlight_string, this time the colors displayed correctly, but the i got the following output, Code: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 <?php function printCode($code, $lines_number = 0) { if (!is_array($code)) $codeE = explode("\n", $code); $count_lines = count($codeE); $r1 = "Code:<br />"; if ($lines_number){ $r1 .= "<div class=\"linenum\">"; foreach($codeE as $line =>$c) { if($count_lines=='1') $r1 .= "1<br>"; else $r1 .= ($line == ($count_lines - 1)) ? "" : ($line+1)."<br />"; } $r1 .= "</div>"; } $r2 = "<div class=\"linetext\">"; $r2 .= highlight_string($code,1); $r2 .= "</div>"; $r .= $r1.$r2; echo "<div class=\"code\">".$r."</div>\n"; } printCode('<?php echo "PHP Code" ?> ',1); ?> Quote Link to comment Share on other sites More sharing options...
gevans Posted June 4, 2009 Share Posted June 4, 2009 Hi, Yeah, i tested those code given by gevans, but it is not displaying any thing there when i add the php code in the test.html file the code that i added in the html file is <pre class="brush: php;"> <?php if (isset($parameter) && $parameter != "") { if ($parameter == "PUBLIC") { $run_result = true; } else if ($parameter == "LOGGED_IN" && isset($_SESSION['userid']) && $_SESSION['userid'] != "" && $_SESSION['userid'] != -1) { $run_result = true; } } ?> </pre> And the output comes as SyntaxHihglighter Test This is a test file to insure that everything is working well. 1. (empty line) So what you're saying is you didn't read the documentation, you don't know how to use it, you implemented it badly, you caused it not to give it, you deemed it useless? Quote Link to comment Share on other sites More sharing options...
gevans Posted June 4, 2009 Share Posted June 4, 2009 Just to prove a point more than anything, I just added the javascript to a page on my server http://projects.purplecoffee.co.uk/syntaxhighlighter/test.html not so hard? Quote Link to comment Share on other sites More sharing options...
scvinodkumar Posted June 4, 2009 Author Share Posted June 4, 2009 Hi gevans, Sorry, i was added the <?php and ?> in the HTML file, that's why it didn't show the result, now i removed it and working fine. I know that i have worked stupidly, i am very sorry for this and wasted your precious time. Thanks for helping you. I will try to avoid making such stupid mistake here after. Quote Link to comment Share on other sites More sharing options...
gevans Posted June 4, 2009 Share Posted June 4, 2009 No worries, just try and make sure you take advantage of suggestions before overlooking them. In most cases when something goes wrong it will be your problem, not the app that you're using. I don't mean that in a bad way, I've pained over the smallest syntax errors myself!! Quote Link to comment 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.