functions.php 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. <?php
  2. // For PHP4 compatability
  3. if(!function_exists('str_ireplace')) {
  4. function str_ireplace($search,$replace,$subject) {
  5. $search = preg_quote($search, "/");
  6. return preg_replace("/".$search."/i", $replace, $subject);
  7. }
  8. }
  9. function PreparePreText($text,$ff='//FF//') {
  10. $text = str_ireplace('<pre',"<||@mpdf@||pre",$text);
  11. $text = str_ireplace('</pre',"<||@mpdf@||/pre",$text);
  12. if ($ff) { $text = str_replace($ff,'</pre><formfeed /><pre>',$text); }
  13. return ('<pre>'.$text.'</pre>');
  14. }
  15. if(!function_exists('strcode2utf')){
  16. function strcode2utf($str,$lo=true) {
  17. //converts all the &#nnn; and &#xhhh; in a string to Unicode
  18. if ($lo) { $lo = 1; } else { $lo = 0; }
  19. $str = preg_replace('/\&\#([0-9]+)\;/me', "code2utf('\\1',{$lo})",$str);
  20. $str = preg_replace('/\&\#x([0-9a-fA-F]+)\;/me', "codeHex2utf('\\1',{$lo})",$str);
  21. return $str;
  22. }
  23. }
  24. if(!function_exists('code2utf')){
  25. function code2utf($num,$lo=true){
  26. //Returns the utf string corresponding to the unicode value
  27. //added notes - http://uk.php.net/utf8_encode
  28. // NB this code initially had 1024 (->2048) and 38000 (-> 65536)
  29. if ($num<128) {
  30. if ($lo) return chr($num);
  31. else return '&#'.$num.';'; // i.e. no change
  32. }
  33. if ($num<2048) return chr(($num>>6)+192).chr(($num&63)+128);
  34. if ($num<65536) return chr(($num>>12)+224).chr((($num>>6)&63)+128).chr(($num&63)+128);
  35. // mPDF 3.0
  36. if ($num<2097152) return chr(($num>>18)+240).chr((($num>>12)&63)+128).chr((($num>>6)&63)+128) .chr(($num&63)+128);
  37. return '?';
  38. }
  39. }
  40. if(!function_exists('codeHex2utf')){
  41. function codeHex2utf($hex,$lo=true){
  42. $num = hexdec($hex);
  43. if (($num<128) && !$lo) return '&#x'.$hex.';'; // i.e. no change
  44. return code2utf($num,$lo);
  45. }
  46. }
  47. ?>