Last active
February 8, 2021 07:40
-
-
Save manh-trinhquoc/0075a3c9777f5588afbf9461741548c1 to your computer and use it in GitHub Desktop.
php snippet
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* xóa bỏ khoảng trắng trong số điện thoại | |
* | |
* @param [type] $text | |
* @return void | |
*/ | |
function remove_blank_space($text) { | |
$result = str_replace(" ", "", $text); | |
return $result; | |
} | |
/** | |
* nếu < 10 thì thêm số 0 ở trước: 01, 02, 03... | |
* | |
* @param [type] $count | |
* @return void | |
*/ | |
function format_slide_count($count) { | |
return $count < 10 ? '0' .$count : $count; | |
} | |
/** | |
* 9 php super global. discourage to use $GLOBALS and $_REQUEST | |
* other pre-set variable see phpinfo() output | |
*/ | |
$GLOBALS; | |
$_GET; | |
$_POST; | |
$_FILES; | |
$_COOKIE; | |
$_REQUEST; | |
$_SESSION; | |
$_SERVER; | |
$_ENV; | |
/** | |
* list all function argument | |
*/ | |
function some_function( $arg1, $arg2 ) { | |
$numargs = func_get_args(); | |
var_dump("test"); | |
var_dump($numargs); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Determine the mobile operating system. | |
* This function returns one of 'iOS', 'Android', 'Windows Phone', or 'unknown'. | |
* | |
* @returns {String} | |
*/ | |
function getMobileOperatingSystem() { | |
if((!isset($_SERVER['HTTP_USER_AGENT'])) || empty($_SERVER['HTTP_USER_AGENT'])) { | |
return "unknown"; | |
} | |
$user_agent = $_SERVER['HTTP_USER_AGENT']; | |
// Windows Phone must come first because its UA also contains "Android" | |
if (preg_match("/windows phone/i", $user_agent)) { | |
return "Windows Phone"; | |
} | |
if (preg_match("/android/i", $user_agent)) { | |
return "Android"; | |
} | |
// iOS detection from: http://stackoverflow.com/a/9039885/177710 | |
if (preg_match("/iPad|iPhone|iPod/i", $user_agent)) { | |
return "iOS"; | |
} | |
return "unknown"; | |
} | |
function getFormatedMobileOperatingSystem() { | |
//format lại kết quả từ hàm getMobileOperatingSystem() để chỉ bỏ dấu cách, uppercase | |
$user_agent = getMobileOperatingSystem(); | |
$user_agent = strtolower($user_agent); | |
$user_agent = preg_replace('/[\W]/', '-', $user_agent); | |
return $user_agent; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment