PageRenderTime 36ms CodeModel.GetById 15ms RepoModel.GetById 1ms app.codeStats 0ms

/protected/vendors/mpdf/includes/functions.php

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