alternative to print_r with syntax highlight


/ Published in: PHP
Save to your folder(s)

alternative to print_r with syntax highlight using jquery


Copy this code and paste it in your HTML
  1. function test($var, $lang = 'php', $apenas_var = true, $die = true){
  2. if($apenas_var)
  3. echo '<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script>';
  4. echo '<script type="text/javascript" src="http://github.com/balupton/jquery-syntaxhighlighter/raw/master/scripts/jquery.syntaxhighlighter.min.js"></script>';
  5. echo '<script type="text/javascript">$.SyntaxHighlighter.init();</script>';
  6. echo '';
  7. echo '<code id="printR" class="language-'.$lang.'" style="margin:50px 10%; width:80%;">';
  8. if($lang == 'html')
  9. echo htmlentities($var);
  10. else
  11. print_r($var);
  12. echo '</code>';
  13. if($die){
  14. die('end');
  15. }
  16. }

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.