Posted By

Bajotumn on 03/27/10


Tagged


Versions (?)

my debug shit


 / Published in: PHP
 

  1. function GetDbgTxt($txt, $explain = null, $htmlentities = true) {
  2. if ($txt == null || $txt == '') {
  3. $txt = "NULL";
  4. }
  5. $out = '';
  6. if ($explain) {
  7. if($htmlentities){
  8. $out = htmlentities(print_r($explain, true));
  9. }else{
  10. $out = print_r($explain, true);
  11. }
  12. $out .= CRLF;
  13. }
  14. if($htmlentities){
  15. $out .= htmlentities(print_r($txt, true));
  16. }else{
  17. $out .= print_r($txt, true);
  18. }
  19.  
  20. return $out;
  21. }
  22. function DebugBoth($data, $explain = null){
  23. DebugPrint($data, $explain);
  24. DebugLog($data, $explain);
  25. }
  26. function DebugLog($data, $explain = null) {
  27. $fh = fopen('Debug.txt', 'a') or die("Unable to open debug log.");
  28. fwrite($fh, '---' . date(FULL_DATE_FORMAT) . '---' . CRLF . GetDbgTxt($data, $explain, false));
  29. fclose($fh);
  30. }
  31. function DebugPrint($data, $explain = null, $nl2br = false) {
  32. global $Bajotumn_pagelevel_debug;
  33. if (isset($Bajotumn_pagelevel_debug)) {
  34. if ($Bajotumn_pagelevel_debug) {
  35. $out = GetDbgTxt($data, $explain);
  36. if ($nl2br == true) {
  37. $out = nl2br($out);
  38. }
  39. echo "<pre>$out</pre>";
  40. }
  41. }
  42. }

Report this snippet  

You need to login to post a comment.