]>
git.immae.eu Git - github/wallabag/wallabag.git/blob - inc/3rdparty/libraries/mpdf/includes/functions.php
4 function array_insert(&$array, $value, $offset) {
5 if (is_array($array)) {
6 $array = array_values($array);
7 $offset = intval($offset);
8 if ($offset < 0 || $offset >= count($array)) { array_push($
array, $value
); }
9 else if ($offset == 0) { array_unshift($
array, $value
); }
11 $temp = array_slice($array, 0, $offset);
12 array_push($temp, $value);
13 $array = array_slice($array, $offset);
14 $array = array_merge($temp, $array);
17 else { $
array = array($value
); }
21 function urlencode_part($url) { // mPDF 5.6.02
22 if (!preg_match('/^[a-z]+:\/\//i',$url)) { return $url
; }
25 if (preg_match('/[?]/',$url)) {
26 $bits = preg_split('/[?]/',$url,2);
30 $file = str_replace(array(" ","!","$","&","'","(",")","*","+",",",";","="),array("%20","%21","%24","%26","%27","%28","%29","%2A","%2B","%2C","%3B","%3D"),$file);
35 function _strspn($str1, $str2, $start=null, $length=null) {
36 $numargs = func_num_args();
38 return strspn($str1, $str2);
40 else if ($numargs == 3) {
41 return strspn($str1, $str2, $start);
44 return strspn($str1, $str2, $start, $length);
49 function _strcspn($str1, $str2, $start=null, $length=null) {
50 $numargs = func_num_args();
52 return strcspn($str1, $str2);
54 else if ($numargs == 3) {
55 return strcspn($str1, $str2, $start);
58 return strcspn($str1, $str2, $start, $length);
62 function _fgets (&$h, $force=false) {
63 $startpos = ftell($h);
65 if ($force && preg_match("/^([^\r\n]*[\r\n]{1,2})(.)/",trim($s), $ns)) {
67 fseek($h,$startpos+strlen($s));
73 // For PHP4 compatability
74 if(!function_exists('str_ireplace
')) {
75 function str_ireplace($search,$replace,$subject) {
76 $search = preg_quote($search, "/");
77 return preg_replace("/".$search."/i", $replace, $subject);
80 if(!function_exists('htmlspecialchars_decode
')) {
81 function htmlspecialchars_decode ($str) {
82 return strtr($str, array_flip(get_html_translation_table(HTML_SPECIALCHARS)));
86 function PreparePreText($text,$ff='//FF//') {
87 $text = htmlspecialchars($text);
88 if ($ff) { $text
= str_replace($ff
,'</pre><formfeed /><pre>',$text
); }
89 return ('<pre>'.$text.'</pre>');
92 if(!function_exists('strcode2utf')){
93 function strcode2utf($str,$lo=true) {
94 //converts all the &#nnn; and &#xhhh; in a string to Unicode
95 if ($lo) { $lo
= 1; } else { $lo
= 0; }
96 $str = preg_replace('/\&\#([0-9]+)\;/me', "code2utf('\\1',{$lo})",$str);
97 $str = preg_replace('/\&\#x([0-9a-fA-F]+)\;/me', "codeHex2utf('\\1',{$lo})",$str);
102 if(!function_exists('code2utf')){
103 function code2utf($num,$lo=true){
104 //Returns the utf string corresponding to the unicode value
106 if ($lo) return chr($num);
107 else return '&#'.$num.';';
109 if ($num<2048) return chr(($num>>6)+
192).chr(($num&63)+
128);
110 if ($num<65536) return chr(($num>>12)+
224).chr((($num>>6)&63)+
128).chr(($num&63)+
128);
111 if ($num<2097152) return chr(($num>>18)+
240).chr((($num>>12)&63)+
128).chr((($num>>6)&63)+
128) .chr(($num&63)+
128);
117 if(!function_exists('codeHex2utf')){
118 function codeHex2utf($hex,$lo=true){
120 if (($num<128) && !$lo) return '&#x'.$hex.';';
121 return code2utf($num,$lo);