functions.php 2.6 KB

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