root/tags/2.1.1/wp-includes/compat.php

Revision 4495, 2.6 kB (checked in by ryan, 2 years ago)

Remove trailing spaces and convert spaces to tabs. Props Nazgul. fixes #986

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
Line 
1 <?php
2
3 /* Functions missing from older PHP versions */
4
5
6 /* Added in PHP 4.2.0 */
7
8 if (!function_exists('floatval')) {
9     function floatval($string) {
10         return ((float) $string);
11     }
12 }
13
14 if (!function_exists('is_a')) {
15     function is_a($object, $class) {
16         // by Aidan Lister <aidan@php.net>
17         if (get_class($object) == strtolower($class)) {
18             return true;
19         } else {
20             return is_subclass_of($object, $class);
21         }
22     }
23 }
24
25 if (!function_exists('ob_clean')) {
26     function ob_clean() {
27         // by Aidan Lister <aidan@php.net>
28         if (@ob_end_clean()) {
29             return ob_start();
30         }
31         return false;
32     }
33 }
34
35
36 /* Added in PHP 4.3.0 */
37
38 function printr($var, $do_not_echo = false) {
39     // from php.net/print_r user contributed notes
40     ob_start();
41     print_r($var);
42     $code htmlentities(ob_get_contents());
43     ob_clean();
44     if (!$do_not_echo) {
45         echo "<pre>$code</pre>";
46     }
47     ob_end_clean();
48     return $code;
49 }
50
51 /* compatibility with PHP versions older than 4.3 */
52 if ( !function_exists('file_get_contents') ) {
53     function file_get_contents( $file ) {
54         $file = file($file);
55         return !$file ? false : implode('', $file);
56     }
57 }
58
59 if (!defined('CASE_LOWER')) {
60         define('CASE_LOWER', 0);
61 }
62
63 if (!defined('CASE_UPPER')) {
64         define('CASE_UPPER', 1);
65 }
66
67
68 /**
69  * Replace array_change_key_case()
70  *
71  * @category    PHP
72  * @package     PHP_Compat
73  * @link        http://php.net/function.array_change_key_case
74  * @author      Stephan Schmidt <schst@php.net>
75  * @author      Aidan Lister <aidan@php.net>
76  * @version     $Revision$
77  * @since       PHP 4.2.0
78  * @require     PHP 4.0.0 (user_error)
79  */
80 if (!function_exists('array_change_key_case')) {
81         function array_change_key_case($input, $case = CASE_LOWER)
82         {
83                 if (!is_array($input)) {
84                         user_error('array_change_key_case(): The argument should be an array',
85                                 E_USER_WARNING);
86                         return false;
87                 }
88
89                 $output   = array ();
90                 $keys     = array_keys($input);
91                 $casefunc = ($case == CASE_LOWER) ? 'strtolower' : 'strtoupper';
92
93                 foreach ($keys as $key) {
94                         $output[$casefunc($key)] = $input[$key];
95                 }
96
97                 return $output;
98         }
99 }
100
101 // From php.net
102 if(!function_exists('http_build_query')) {
103      function http_build_query( $formdata, $numeric_prefix = null, $key = null ) {
104              $res = array();
105              foreach ((array)$formdata as $k=>$v) {
106                      $tmp_key = urlencode(is_int($k) ? $numeric_prefix.$k : $k);
107                      if ($key) $tmp_key = $key.'['.$tmp_key.']';
108                      $res[] = ( ( is_array($v) || is_object($v) ) ? http_build_query($v, null, $tmp_key) : $tmp_key."=".urlencode($v) );
109              }
110              $separator = ini_get('arg_separator.output');
111              return implode($separator, $res);
112      }
113 }
114
115 if ( !function_exists('_') ) {
116     function _($string) {
117         return $string;
118     }
119 }
120
121 ?>
122
Note: See TracBrowser for help on using the browser.