blob: b4bd5b09708e5939371cee066398d943aebf43f2 [file] [log] [blame]
Derek Allard2067d1a2008-11-13 22:59:24 +00001<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
2/**
3 * CodeIgniter
4 *
Greg Aker741de1c2010-11-10 14:52:57 -06005 * An open source application development framework for PHP 5.1.6 or newer
Derek Allard2067d1a2008-11-13 22:59:24 +00006 *
7 * @package CodeIgniter
8 * @author ExpressionEngine Dev Team
Greg Aker0711dc82011-01-05 10:49:40 -06009 * @copyright Copyright (c) 2008 - 2011, EllisLab, Inc.
Derek Allard2067d1a2008-11-13 22:59:24 +000010 * @license http://codeigniter.com/user_guide/license.html
11 * @link http://codeigniter.com
12 * @since Version 1.0
13 * @filesource
14 */
15
16// ------------------------------------------------------------------------
17
18/**
Derek Jonesdc8e9ea2010-03-02 13:17:19 -060019 * Common Functions
20 *
21 * Loads the base classes and executes the request.
22 *
23 * @package CodeIgniter
24 * @subpackage codeigniter
25 * @category Common Functions
26 * @author ExpressionEngine Dev Team
27 * @link http://codeigniter.com/user_guide/
28 */
29
30// ------------------------------------------------------------------------
31
32/**
Derek Jones086ee5a2009-07-28 14:42:12 +000033* Determines if the current version of PHP is greater then the supplied value
34*
35* Since there are a few places where we conditionally test for PHP > 5
36* we'll set a static variable.
37*
38* @access public
Derek Jones77b513b2009-08-06 14:39:25 +000039* @param string
Derek Jonesdc8e9ea2010-03-02 13:17:19 -060040* @return bool TRUE if the current version is $version or higher
Derek Jones086ee5a2009-07-28 14:42:12 +000041*/
Derek Jonesdc8e9ea2010-03-02 13:17:19 -060042 function is_php($version = '5.0.0')
Derek Jones086ee5a2009-07-28 14:42:12 +000043 {
Derek Jonesdc8e9ea2010-03-02 13:17:19 -060044 static $_is_php;
45 $version = (string)$version;
Barry Mienydd671972010-10-04 16:33:58 +020046
Derek Jonesdc8e9ea2010-03-02 13:17:19 -060047 if ( ! isset($_is_php[$version]))
48 {
49 $_is_php[$version] = (version_compare(PHP_VERSION, $version) < 0) ? FALSE : TRUE;
50 }
Derek Jones086ee5a2009-07-28 14:42:12 +000051
Derek Jonesdc8e9ea2010-03-02 13:17:19 -060052 return $_is_php[$version];
53 }
Derek Jones5bcfd2e2009-07-28 14:42:42 +000054
Derek Jones086ee5a2009-07-28 14:42:12 +000055// ------------------------------------------------------------------------
56
57/**
Derek Allard2067d1a2008-11-13 22:59:24 +000058 * Tests for file writability
59 *
Barry Mienydd671972010-10-04 16:33:58 +020060 * is_writable() returns TRUE on Windows servers when you really can't write to
Derek Allard2067d1a2008-11-13 22:59:24 +000061 * the file, based on the read-only attribute. is_writable() is also unreliable
Derek Jonesdc8e9ea2010-03-02 13:17:19 -060062 * on Unix servers if safe_mode is on.
Derek Allard2067d1a2008-11-13 22:59:24 +000063 *
64 * @access private
65 * @return void
Barry Mienydd671972010-10-04 16:33:58 +020066 */
Derek Jonesdc8e9ea2010-03-02 13:17:19 -060067 function is_really_writable($file)
Derek Allard2067d1a2008-11-13 22:59:24 +000068 {
Derek Jonesdc8e9ea2010-03-02 13:17:19 -060069 // If we're on a Unix server with safe_mode off we call is_writable
70 if (DIRECTORY_SEPARATOR == '/' AND @ini_get("safe_mode") == FALSE)
71 {
72 return is_writable($file);
73 }
Derek Allard2067d1a2008-11-13 22:59:24 +000074
Derek Jonesdc8e9ea2010-03-02 13:17:19 -060075 // For windows servers and safe_mode "on" installations we'll actually
76 // write a file then read it. Bah...
77 if (is_dir($file))
78 {
79 $file = rtrim($file, '/').'/'.md5(mt_rand(1,100).mt_rand(1,100));
Derek Allard2067d1a2008-11-13 22:59:24 +000080
Derek Jonesdc8e9ea2010-03-02 13:17:19 -060081 if (($fp = @fopen($file, FOPEN_WRITE_CREATE)) === FALSE)
82 {
83 return FALSE;
84 }
85
86 fclose($fp);
87 @chmod($file, DIR_WRITE_MODE);
88 @unlink($file);
89 return TRUE;
90 }
Eric Barnes15083012011-03-21 22:13:12 -040091 elseif ( ! is_file($file) OR ($fp = @fopen($file, FOPEN_WRITE_CREATE)) === FALSE)
Derek Allard2067d1a2008-11-13 22:59:24 +000092 {
93 return FALSE;
94 }
95
96 fclose($fp);
Derek Allard2067d1a2008-11-13 22:59:24 +000097 return TRUE;
98 }
Derek Allard2067d1a2008-11-13 22:59:24 +000099
100// ------------------------------------------------------------------------
101
102/**
103* Class registry
104*
105* This function acts as a singleton. If the requested class does not
106* exist it is instantiated and set to a static variable. If it has
107* previously been instantiated the variable is returned.
108*
109* @access public
110* @param string the class name being requested
Derek Jonesdc8e9ea2010-03-02 13:17:19 -0600111* @param string the directory where the class should be found
112* @param string the class name prefix
Derek Allard2067d1a2008-11-13 22:59:24 +0000113* @return object
114*/
Derek Jonesdc8e9ea2010-03-02 13:17:19 -0600115 function &load_class($class, $directory = 'libraries', $prefix = 'CI_')
Derek Allard2067d1a2008-11-13 22:59:24 +0000116 {
Derek Jonesdc8e9ea2010-03-02 13:17:19 -0600117 static $_classes = array();
Barry Mienydd671972010-10-04 16:33:58 +0200118
Derek Jonesdc8e9ea2010-03-02 13:17:19 -0600119 // Does the class exist? If so, we're done...
120 if (isset($_classes[$class]))
Derek Allard2067d1a2008-11-13 22:59:24 +0000121 {
Derek Jonesdc8e9ea2010-03-02 13:17:19 -0600122 return $_classes[$class];
Derek Allard2067d1a2008-11-13 22:59:24 +0000123 }
Derek Jonesdc8e9ea2010-03-02 13:17:19 -0600124
125 $name = FALSE;
126
127 // Look for the class first in the native system/libraries folder
128 // thenin the local application/libraries folder
129 foreach (array(BASEPATH, APPPATH) as $path)
Barry Mienydd671972010-10-04 16:33:58 +0200130 {
Derek Jonesdc8e9ea2010-03-02 13:17:19 -0600131 if (file_exists($path.$directory.'/'.$class.EXT))
132 {
133 $name = $prefix.$class;
Barry Mienydd671972010-10-04 16:33:58 +0200134
Derek Jonesdc8e9ea2010-03-02 13:17:19 -0600135 if (class_exists($name) === FALSE)
136 {
137 require($path.$directory.'/'.$class.EXT);
138 }
Barry Mienydd671972010-10-04 16:33:58 +0200139
Derek Jonesdc8e9ea2010-03-02 13:17:19 -0600140 break;
141 }
142 }
143
144 // Is the request a class extension? If so we load it too
Phil Sturgeon3140ad52010-03-12 00:22:42 +0000145 if (file_exists(APPPATH.$directory.'/'.config_item('subclass_prefix').$class.EXT))
Barry Mienydd671972010-10-04 16:33:58 +0200146 {
Derek Jonesdc8e9ea2010-03-02 13:17:19 -0600147 $name = config_item('subclass_prefix').$class;
Barry Mienydd671972010-10-04 16:33:58 +0200148
Derek Jonesdc8e9ea2010-03-02 13:17:19 -0600149 if (class_exists($name) === FALSE)
150 {
Phil Sturgeon3140ad52010-03-12 00:22:42 +0000151 require(APPPATH.$directory.'/'.config_item('subclass_prefix').$class.EXT);
Derek Jonesdc8e9ea2010-03-02 13:17:19 -0600152 }
153 }
154
155 // Did we find the class?
156 if ($name === FALSE)
Derek Allard2067d1a2008-11-13 22:59:24 +0000157 {
Barry Mienydd671972010-10-04 16:33:58 +0200158 // Note: We use exit() rather then show_error() in order to avoid a
159 // self-referencing loop with the Excptions class
Derek Jonesdc8e9ea2010-03-02 13:17:19 -0600160 exit('Unable to locate the specified class: '.$class.EXT);
Derek Allard2067d1a2008-11-13 22:59:24 +0000161 }
Derek Jonesdc8e9ea2010-03-02 13:17:19 -0600162
163 // Keep track of what we just loaded
164 is_loaded($class);
165
Pascal Kriete58560022010-11-10 16:01:20 -0500166 $_classes[$class] = new $name();
Derek Jonesdc8e9ea2010-03-02 13:17:19 -0600167 return $_classes[$class];
Derek Allard2067d1a2008-11-13 22:59:24 +0000168 }
169
Derek Jonesdc8e9ea2010-03-02 13:17:19 -0600170// --------------------------------------------------------------------
171
172/**
173* Keeps track of which libraries have been loaded. This function is
174* called by the load_class() function above
175*
176* @access public
177* @return array
178*/
179 function is_loaded($class = '')
180 {
181 static $_is_loaded = array();
182
183 if ($class != '')
184 {
185 $_is_loaded[strtolower($class)] = $class;
186 }
187
188 return $_is_loaded;
189 }
190
191// ------------------------------------------------------------------------
Derek Jonesf0a9b332009-07-29 14:19:18 +0000192
193/**
Derek Allard2067d1a2008-11-13 22:59:24 +0000194* Loads the main config.php file
195*
Derek Jonesdc8e9ea2010-03-02 13:17:19 -0600196* This function lets us grab the config file even if the Config class
197* hasn't been instantiated yet
198*
Derek Allard2067d1a2008-11-13 22:59:24 +0000199* @access private
200* @return array
201*/
Derek Jonesdc8e9ea2010-03-02 13:17:19 -0600202 function &get_config($replace = array())
Derek Allard2067d1a2008-11-13 22:59:24 +0000203 {
Derek Jonesdc8e9ea2010-03-02 13:17:19 -0600204 static $_config;
Barry Mienydd671972010-10-04 16:33:58 +0200205
Derek Jonesdc8e9ea2010-03-02 13:17:19 -0600206 if (isset($_config))
207 {
208 return $_config[0];
Barry Mienydd671972010-10-04 16:33:58 +0200209 }
Derek Jonesdc8e9ea2010-03-02 13:17:19 -0600210
joelcox2035fd82011-01-16 16:50:36 +0100211 $file_path = APPPATH.'config/'.ENVIRONMENT.'/config'.EXT;
212
Derek Jonesdc8e9ea2010-03-02 13:17:19 -0600213 // Fetch the config file
joelcox2035fd82011-01-16 16:50:36 +0100214 if ( ! file_exists($file_path))
Derek Allard2067d1a2008-11-13 22:59:24 +0000215 {
joelcox2035fd82011-01-16 16:50:36 +0100216 $file_path = APPPATH.'config/config'.EXT;
217
218 if ( ! file_exists($file_path))
219 {
220 exit('The configuration file does not exist.');
221 }
Derek Jonesdc8e9ea2010-03-02 13:17:19 -0600222 }
joelcox2035fd82011-01-16 16:50:36 +0100223
224 require($file_path);
Derek Allard2067d1a2008-11-13 22:59:24 +0000225
Derek Jonesdc8e9ea2010-03-02 13:17:19 -0600226 // Does the $config array exist in the file?
Derek Allard2067d1a2008-11-13 22:59:24 +0000227 if ( ! isset($config) OR ! is_array($config))
228 {
229 exit('Your config file does not appear to be formatted correctly.');
230 }
231
Derek Jonesdc8e9ea2010-03-02 13:17:19 -0600232 // Are any values being dynamically replaced?
233 if (count($replace) > 0)
234 {
235 foreach ($replace as $key => $val)
236 {
237 if (isset($config[$key]))
238 {
239 $config[$key] = $val;
240 }
241 }
242 }
Barry Mienydd671972010-10-04 16:33:58 +0200243
Derek Jonesdc8e9ea2010-03-02 13:17:19 -0600244 return $_config[0] =& $config;
Derek Allard2067d1a2008-11-13 22:59:24 +0000245 }
Derek Jonesdc8e9ea2010-03-02 13:17:19 -0600246
247// ------------------------------------------------------------------------
Derek Allard2067d1a2008-11-13 22:59:24 +0000248
249/**
Derek Jonesdc8e9ea2010-03-02 13:17:19 -0600250* Returns the specified config item
Derek Allard2067d1a2008-11-13 22:59:24 +0000251*
252* @access public
253* @return mixed
254*/
Derek Jonesdc8e9ea2010-03-02 13:17:19 -0600255 function config_item($item)
Derek Allard2067d1a2008-11-13 22:59:24 +0000256 {
Derek Jonesdc8e9ea2010-03-02 13:17:19 -0600257 static $_config_item = array();
Barry Mienydd671972010-10-04 16:33:58 +0200258
Derek Jonesdc8e9ea2010-03-02 13:17:19 -0600259 if ( ! isset($_config_item[$item]))
Derek Allard2067d1a2008-11-13 22:59:24 +0000260 {
Derek Jonesdc8e9ea2010-03-02 13:17:19 -0600261 $config =& get_config();
Barry Mienydd671972010-10-04 16:33:58 +0200262
Derek Jonesdc8e9ea2010-03-02 13:17:19 -0600263 if ( ! isset($config[$item]))
264 {
265 return FALSE;
266 }
267 $_config_item[$item] = $config[$item];
Derek Allard2067d1a2008-11-13 22:59:24 +0000268 }
Barry Mienydd671972010-10-04 16:33:58 +0200269
Derek Jonesdc8e9ea2010-03-02 13:17:19 -0600270 return $_config_item[$item];
Derek Allard2067d1a2008-11-13 22:59:24 +0000271 }
272
Derek Jonesdc8e9ea2010-03-02 13:17:19 -0600273// ------------------------------------------------------------------------
Derek Allard2067d1a2008-11-13 22:59:24 +0000274
275/**
276* Error Handler
277*
278* This function lets us invoke the exception class and
279* display errors using the standard error template located
280* in application/errors/errors.php
281* This function will send the error page directly to the
282* browser and exit.
283*
284* @access public
285* @return void
286*/
Derek Jonesdc8e9ea2010-03-02 13:17:19 -0600287 function show_error($message, $status_code = 500, $heading = 'An Error Was Encountered')
288 {
289 $_error =& load_class('Exceptions', 'core');
290 echo $_error->show_error($heading, $message, 'error_general', $status_code);
291 exit;
292 }
Derek Allard2067d1a2008-11-13 22:59:24 +0000293
Derek Jonesdc8e9ea2010-03-02 13:17:19 -0600294// ------------------------------------------------------------------------
Derek Allard2067d1a2008-11-13 22:59:24 +0000295
296/**
297* 404 Page Handler
298*
299* This function is similar to the show_error() function above
300* However, instead of the standard error template it displays
301* 404 errors.
302*
303* @access public
304* @return void
305*/
Derek Allard2ddc9492010-08-05 10:08:33 -0400306 function show_404($page = '', $log_error = TRUE)
Derek Jonesdc8e9ea2010-03-02 13:17:19 -0600307 {
308 $_error =& load_class('Exceptions', 'core');
Derek Allard2ddc9492010-08-05 10:08:33 -0400309 $_error->show_404($page, $log_error);
Derek Jonesdc8e9ea2010-03-02 13:17:19 -0600310 exit;
311 }
Derek Allard2067d1a2008-11-13 22:59:24 +0000312
Derek Jonesdc8e9ea2010-03-02 13:17:19 -0600313// ------------------------------------------------------------------------
Derek Allard2067d1a2008-11-13 22:59:24 +0000314
315/**
316* Error Logging Interface
317*
318* We use this as a simple mechanism to access the logging
319* class and send messages to be logged.
320*
321* @access public
322* @return void
323*/
Derek Jonesdc8e9ea2010-03-02 13:17:19 -0600324 function log_message($level = 'error', $message, $php_error = FALSE)
Derek Allard2067d1a2008-11-13 22:59:24 +0000325 {
Derek Jonesdc8e9ea2010-03-02 13:17:19 -0600326 static $_log;
327
328 if (config_item('log_threshold') == 0)
329 {
330 return;
331 }
Barry Mienydd671972010-10-04 16:33:58 +0200332
Derek Jonesdc8e9ea2010-03-02 13:17:19 -0600333 $_log =& load_class('Log');
334 $_log->write_log($level, $message, $php_error);
Derek Allard2067d1a2008-11-13 22:59:24 +0000335 }
336
Derek Jonesdc8e9ea2010-03-02 13:17:19 -0600337// ------------------------------------------------------------------------
Derek Jones817163a2009-07-11 17:05:58 +0000338
339/**
340 * Set HTTP Status Header
341 *
342 * @access public
Barry Mienydd671972010-10-04 16:33:58 +0200343 * @param int the status code
344 * @param string
Derek Jones817163a2009-07-11 17:05:58 +0000345 * @return void
Barry Mienydd671972010-10-04 16:33:58 +0200346 */
Derek Jonesdc8e9ea2010-03-02 13:17:19 -0600347 function set_status_header($code = 200, $text = '')
Derek Jones817163a2009-07-11 17:05:58 +0000348 {
Derek Jonesdc8e9ea2010-03-02 13:17:19 -0600349 $stati = array(
350 200 => 'OK',
351 201 => 'Created',
352 202 => 'Accepted',
353 203 => 'Non-Authoritative Information',
354 204 => 'No Content',
355 205 => 'Reset Content',
356 206 => 'Partial Content',
Derek Jones817163a2009-07-11 17:05:58 +0000357
Derek Jonesdc8e9ea2010-03-02 13:17:19 -0600358 300 => 'Multiple Choices',
359 301 => 'Moved Permanently',
360 302 => 'Found',
361 304 => 'Not Modified',
362 305 => 'Use Proxy',
363 307 => 'Temporary Redirect',
364
365 400 => 'Bad Request',
366 401 => 'Unauthorized',
367 403 => 'Forbidden',
368 404 => 'Not Found',
369 405 => 'Method Not Allowed',
370 406 => 'Not Acceptable',
371 407 => 'Proxy Authentication Required',
372 408 => 'Request Timeout',
373 409 => 'Conflict',
374 410 => 'Gone',
375 411 => 'Length Required',
376 412 => 'Precondition Failed',
377 413 => 'Request Entity Too Large',
378 414 => 'Request-URI Too Long',
379 415 => 'Unsupported Media Type',
380 416 => 'Requested Range Not Satisfiable',
381 417 => 'Expectation Failed',
382
383 500 => 'Internal Server Error',
384 501 => 'Not Implemented',
385 502 => 'Bad Gateway',
386 503 => 'Service Unavailable',
387 504 => 'Gateway Timeout',
388 505 => 'HTTP Version Not Supported'
389 );
390
391 if ($code == '' OR ! is_numeric($code))
392 {
393 show_error('Status codes must be numeric', 500);
394 }
395
396 if (isset($stati[$code]) AND $text == '')
Barry Mienydd671972010-10-04 16:33:58 +0200397 {
Derek Jonesdc8e9ea2010-03-02 13:17:19 -0600398 $text = $stati[$code];
399 }
Barry Mienydd671972010-10-04 16:33:58 +0200400
Derek Jonesdc8e9ea2010-03-02 13:17:19 -0600401 if ($text == '')
402 {
403 show_error('No status text available. Please check your status code number or supply your own message text.', 500);
404 }
Barry Mienydd671972010-10-04 16:33:58 +0200405
Derek Jonesdc8e9ea2010-03-02 13:17:19 -0600406 $server_protocol = (isset($_SERVER['SERVER_PROTOCOL'])) ? $_SERVER['SERVER_PROTOCOL'] : FALSE;
407
408 if (substr(php_sapi_name(), 0, 3) == 'cgi')
409 {
410 header("Status: {$code} {$text}", TRUE);
411 }
412 elseif ($server_protocol == 'HTTP/1.1' OR $server_protocol == 'HTTP/1.0')
413 {
414 header($server_protocol." {$code} {$text}", TRUE, $code);
415 }
416 else
417 {
418 header("HTTP/1.1 {$code} {$text}", TRUE, $code);
419 }
Derek Jones817163a2009-07-11 17:05:58 +0000420 }
Barry Mienydd671972010-10-04 16:33:58 +0200421
Derek Jonesdc8e9ea2010-03-02 13:17:19 -0600422// --------------------------------------------------------------------
Derek Jones817163a2009-07-11 17:05:58 +0000423
Derek Allard2067d1a2008-11-13 22:59:24 +0000424/**
425* Exception Handler
426*
427* This is the custom exception handler that is declaired at the top
Derek Jonesdc8e9ea2010-03-02 13:17:19 -0600428* of Codeigniter.php. The main reason we use this is to permit
429* PHP errors to be logged in our own log files since the user may
Derek Allard2067d1a2008-11-13 22:59:24 +0000430* not have access to server logs. Since this function
431* effectively intercepts PHP errors, however, we also need
432* to display errors based on the current error_reporting level.
433* We do that with the use of a PHP error template.
434*
435* @access private
436* @return void
437*/
Derek Jonesdc8e9ea2010-03-02 13:17:19 -0600438 function _exception_handler($severity, $message, $filepath, $line)
Barry Mienydd671972010-10-04 16:33:58 +0200439 {
Derek Jonesdc8e9ea2010-03-02 13:17:19 -0600440 // We don't bother with "strict" notices since they tend to fill up
441 // the log file with excess information that isn't normally very helpful.
Barry Mienydd671972010-10-04 16:33:58 +0200442 // For example, if you are running PHP 5 and you use version 4 style
443 // class functions (without prefixes like "public", "private", etc.)
Derek Jonesdc8e9ea2010-03-02 13:17:19 -0600444 // you'll get notices telling you that these have been deprecated.
445 if ($severity == E_STRICT)
446 {
447 return;
448 }
Barry Mienydd671972010-10-04 16:33:58 +0200449
Derek Jonesdc8e9ea2010-03-02 13:17:19 -0600450 $_error =& load_class('Exceptions', 'core');
Barry Mienydd671972010-10-04 16:33:58 +0200451
452 // Should we display the error? We'll get the current error_reporting
Derek Jonesdc8e9ea2010-03-02 13:17:19 -0600453 // level and add its bits with the severity bits to find out.
454 if (($severity & error_reporting()) == $severity)
455 {
456 $_error->show_php_error($severity, $message, $filepath, $line);
457 }
Derek Allard2067d1a2008-11-13 22:59:24 +0000458
Derek Jonesdc8e9ea2010-03-02 13:17:19 -0600459 // Should we log the error? No? We're done...
460 if (config_item('log_threshold') == 0)
461 {
462 return;
463 }
Barry Mienydd671972010-10-04 16:33:58 +0200464
Derek Jonesdc8e9ea2010-03-02 13:17:19 -0600465 $_error->log_exception($severity, $message, $filepath, $line);
466 }
Derek Allard2067d1a2008-11-13 22:59:24 +0000467
Greg Aker757dda62010-04-14 19:06:19 -0500468 // --------------------------------------------------------------------
Barry Mienydd671972010-10-04 16:33:58 +0200469
Greg Aker757dda62010-04-14 19:06:19 -0500470 /**
471 * Remove Invisible Characters
472 *
473 * This prevents sandwiching null characters
474 * between ascii characters, like Java\0script.
475 *
476 * @access public
477 * @param string
478 * @return string
479 */
Pascal Kriete0ff50262011-04-05 14:52:03 -0400480 function remove_invisible_characters($str, $url_encoded = TRUE)
Greg Aker757dda62010-04-14 19:06:19 -0500481 {
Pascal Kriete0ff50262011-04-05 14:52:03 -0400482 $non_displayables = array();
483
484 // every control character except newline (dec 10)
485 // carriage return (dec 13), and horizontal tab (dec 09)
486
487 if ($url_encoded)
Greg Aker757dda62010-04-14 19:06:19 -0500488 {
Pascal Kriete0ff50262011-04-05 14:52:03 -0400489 $non_displayables[] = '/%0[0-8bcef]/'; // url encoded 00-08, 11, 12, 14, 15
490 $non_displayables[] = '/%1[0-9a-f]/'; // url encoded 16-31
Greg Aker757dda62010-04-14 19:06:19 -0500491 }
Pascal Kriete0ff50262011-04-05 14:52:03 -0400492
493 $non_displayables[] = '/[\x00-\x08\x0B\x0C\x0E-\x1F\x7F]+/S'; // 00-08, 11, 12, 14-31, 127
Greg Aker757dda62010-04-14 19:06:19 -0500494
495 do
496 {
Pascal Kriete0ff50262011-04-05 14:52:03 -0400497 $str = preg_replace($non_displayables, '', $str, -1, $count);
Greg Aker757dda62010-04-14 19:06:19 -0500498 }
Pascal Kriete0ff50262011-04-05 14:52:03 -0400499 while ($count);
Greg Aker757dda62010-04-14 19:06:19 -0500500
501 return $str;
502 }
Derek Allard2067d1a2008-11-13 22:59:24 +0000503
504
505/* End of file Common.php */
Derek Jonesc68dfbf2010-03-02 12:59:23 -0600506/* Location: ./system/core/Common.php */