Common function Syntax | Description |
---|---|
is_php($version) | Compares if the PHP version being used is more than the actual version. |
config_item($key) | Configuration item is brought by this function which is a string variable. |
remove_invisible_characters($str[, $url_encoded = TRUE]) | This functions does not allow the insertion of NULL characters in the middle of ASCII characters. |
set_status_header($code[, $text = '']) | The function allows to set a header for the server status manually. |
is_really_writable($file) | Verifies whether the file allows to write or not. |
get_mimes() | This function returns a reference to the MIMEs array from application/config/mimes.php. |
html_escape($var) | This function acts as a native PHP htmlspecialchars() function. |
function_usable($function_name) | This function checks if the function is present or not. If present, it is useful or not. |
is_cli() | Checks if an application can run in the Command Line or not. |
common_function.php
in the file path application/controller and enter the below code.
[php]
<?php
class CommonFun_Controller extends CI_Controller {
public function index() {
set_status_header(200);
echo is_php('5.3')."<br>";
var_dump(is_really_writable('./Form.php'));
echo config_item('language')."<br>";
echo remove_invisible_characters('This is a test','UTF8')."<br>";
$str = '< This > is \' a " test & string';
echo html_escape($str)."<br>";
echo "is_https():".var_dump(is_https())."<br>";
echo "is_cli():".var_dump(is_cli())."<br>";
var_dump(function_usable('test'))."<br>";
echo "get_mimes():".print_r(get_mimes())."<br>";
}
public function test() {
echo "Test function";
}
}
?>
[/php]
Add the route to the above created controller in routes.php
file present in application/config and enter the below code at the end of the file.
[php]
$route['commonfunctions'] = 'CommonFun_Controller';
[/php]