Posted By

pateketrueke on 05/14/09


Tagged

function cheatSheet hilight


Versions (?)

Auto-highlight Cheatsheeter


 / Published in: PHP
 

  1. function report($text = '', $ret = true, $_re = true)
  2. {
  3. $out = array();
  4.  
  5. preg_match_all('/function\s+(&?[a-z]\w+)\s*\(\s*([^\{]*)\s*\)/is', $text, $test);
  6. arsort($test[1]);
  7.  
  8. foreach ($test[1] as $key => $val)
  9. { // evitamos..
  10. if (preg_match('/^[A-Z_]/', $val) && $_re)
  11. {
  12. continue;
  13. }
  14.  
  15. // simple...
  16. $val = htmlspecialchars($val);
  17. $args = htmlspecialchars($test[2][$key]);
  18.  
  19. $args = preg_replace('/(\'|\"|&quot;?)(.*?)\\1/', '<span style="color:green;white-space:nowrap">\\0</span>', $args); // "string's"
  20. $args = preg_replace('/(true|false|null)/i', '<span style="color:purple;font-weight:bold">\\0</span>', $args); // bool's
  21. $args = preg_replace('/\b[0-9]+\b/', '<span style="color:black;font-weight:bold">\\0</span>', $args); // INTs
  22. $args = preg_replace('/\$[a-z0-9_]+/i', '<span style="color:darkblue">\\0</span>',$args); // $vars
  23. $args = preg_replace('/[a-z0-9_]+\(.*?\)/i', '<span style="color:gray">\\0</span>', $args); // array()
  24.  
  25. $args = trim($args)? $args: $args.'<span style="color:black;font-weight:bold;font-style:italic">void</span>';
  26. $args = preg_replace('/\s+=\s+/', '&nbsp;=&nbsp;', $args);
  27. $args = preg_replace('/\s*,\s+/', ',&nbsp;', $args);
  28.  
  29. $out []= "\t<span style=\"color:gray\">
  30. <span style=\"color:red\"><em>$val</em></span><strong>(</strong>$args<strong>)</strong>;
  31. </span>";
  32. }
  33.  
  34. $out = join("\n", $out);
  35.  
  36. if ( ! $ret)
  37. {
  38. echo $ret;
  39. }
  40. return $out;
  41. }

Report this snippet  

You need to login to post a comment.