/application/helpers/mpdf/includes/functions.php

https://gitlab.com/mlnkv/fusioninvoice · PHP · 106 lines · 85 code · 16 blank · 5 comment · 32 complexity · b67d38438110084979c6c93594d05548 MD5 · raw file

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