functions.php 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. <?php
  2. function _strspn($str1, $str2, $start=null, $length=null) {
  3. $numargs = func_num_args();
  4. if ($numargs == 2) {
  5. return strspn($str1, $str2);
  6. }
  7. else if ($numargs == 3) {
  8. return strspn($str1, $str2, $start);
  9. }
  10. else {
  11. return strspn($str1, $str2, $start, $length);
  12. }
  13. }
  14. function _strcspn($str1, $str2, $start=null, $length=null) {
  15. $numargs = func_num_args();
  16. if ($numargs == 2) {
  17. return strcspn($str1, $str2);
  18. }
  19. else if ($numargs == 3) {
  20. return strcspn($str1, $str2, $start);
  21. }
  22. else {
  23. return strcspn($str1, $str2, $start, $length);
  24. }
  25. }
  26. function _fgets (&$h, $force=false) {
  27. $startpos = ftell($h);
  28. $s = fgets($h, 1024);
  29. if ($force && preg_match("/^([^\r\n]*[\r\n]{1,2})(.)/",trim($s), $ns)) {
  30. $s = $ns[1];
  31. fseek($h,$startpos+strlen($s));
  32. }
  33. return $s;
  34. }
  35. // For PHP4 compatability
  36. if(!function_exists('str_ireplace')) {
  37. function str_ireplace($search,$replace,$subject) {
  38. $search = preg_quote($search, "/");
  39. return preg_replace("/".$search."/i", $replace, $subject);
  40. }
  41. }
  42. if(!function_exists('htmlspecialchars_decode')) {
  43. function htmlspecialchars_decode ($str) {
  44. return strtr($str, array_flip(get_html_translation_table(HTML_SPECIALCHARS)));
  45. }
  46. }
  47. function PreparePreText($text,$ff='//FF//') {
  48. // mPDF 5.0.053
  49. $text = htmlspecialchars($text);
  50. if ($ff) { $text = str_replace($ff,'</pre><formfeed /><pre>',$text); }
  51. return ('<pre>'.$text.'</pre>');
  52. }
  53. if(!function_exists('strcode2utf')){
  54. function strcode2utf($str,$lo=true) {
  55. //converts all the &#nnn; and &#xhhh; in a string to Unicode
  56. if ($lo) { $lo = 1; } else { $lo = 0; }
  57. $str = preg_replace('/\&\#([0-9]+)\;/me', "code2utf('\\1',{$lo})",$str);
  58. $str = preg_replace('/\&\#x([0-9a-fA-F]+)\;/me', "codeHex2utf('\\1',{$lo})",$str);
  59. return $str;
  60. }
  61. }
  62. if(!function_exists('code2utf')){
  63. function code2utf($num,$lo=true){
  64. //Returns the utf string corresponding to the unicode value
  65. //added notes - http://uk.php.net/utf8_encode
  66. if ($num<128) {
  67. if ($lo) return chr($num);
  68. else return '&#'.$num.';'; // i.e. no change
  69. }
  70. if ($num<2048) return chr(($num>>6)+192).chr(($num&63)+128);
  71. if ($num<65536) return chr(($num>>12)+224).chr((($num>>6)&63)+128).chr(($num&63)+128);
  72. if ($num<2097152) return chr(($num>>18)+240).chr((($num>>12)&63)+128).chr((($num>>6)&63)+128) .chr(($num&63)+128);
  73. return '?';
  74. }
  75. }
  76. if(!function_exists('codeHex2utf')){
  77. function codeHex2utf($hex,$lo=true){
  78. $num = hexdec($hex);
  79. if (($num<128) && !$lo) return '&#x'.$hex.';'; // i.e. no change
  80. return code2utf($num,$lo);
  81. }
  82. }
  83. ?>