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
// reference: http://stackoverflow.com/a/19785468/2253749 | |
<VirtualHost *:80> | |
ServerName subdomain.yourdomain.com | |
ProxyPreserveHost on | |
ProxyPass / http://localhost:8080/ | |
</VirtualHost> |
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 | |
// reference: http://stackoverflow.com/questions/12553160/getting-visitors-country-from-their-ip | |
function ip_info($ip = NULL, $purpose = "location", $deep_detect = TRUE) { | |
$output = NULL; | |
if (filter_var($ip, FILTER_VALIDATE_IP) === FALSE) { | |
$ip = $_SERVER["REMOTE_ADDR"]; | |
if ($deep_detect) { | |
if (filter_var(@$_SERVER['HTTP_X_FORWARDED_FOR'], FILTER_VALIDATE_IP)) |
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 | |
// reference: http://stackoverflow.com/questions/18685/how-to-display-12-minutes-ago-etc-in-a-php-webpage | |
function timeAgo($timestamp){ | |
$datetime1=new DateTime("now"); | |
$datetime2=date_create($timestamp); | |
$diff=date_diff($datetime1, $datetime2); | |
$timemsg=''; | |
if($diff->y > 0){ | |
$timemsg = $diff->y .' year'. ($diff->y > 1?"'s":''); |
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 | |
//Source http://stackoverflow.com/questions/2477496/php-sort-array-by-subarray-value | |
//Use usort function and custom criteria. | |
function cmp_by_optionNumber($a, $b) { | |
return $a["optionNumber"] - $b["optionNumber"]; | |
} | |
//and |
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 | |
//Source http://stackoverflow.com/questions/13329621/count-sub-elements-of-an-array-in-php | |
function array_count ($array, $key, $value = NULL) { | |
// count($array[*][$key]) | |
$c = 0; | |
if (is_null($value)) { | |
foreach ($array as $i=>$subarray) { | |
$c += ($subarray[$key]!=''); | |
} |
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 | |
//source: http://stackoverflow.com/questions/1019076/how-to-search-by-key-value-in-a-multidimensional-array-in-php | |
function search($array, $key, $value) { | |
$results = array(); | |
if (is_array($array)) { | |
if (isset($array[$key]) && $array[$key] == $value) { | |
$results[] = $array; | |
} |
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 | |
function chineseToUnicode( $str ){ | |
$str = rawurlencode( $str ); | |
$str = str_replace("%", "", $str); | |
return $str; | |
} | |
//Print result | |
$str = "旴"; |
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 | |
//php自帶的basename函數不支持中文,下面這個方法是最簡單的實現。 | |
function get_basename($filename){ | |
return preg_replace('/^.+[\\\\\\/]/', '', $filename); | |
} |
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
//參考 http://stackoverflow.com/questions/5867370/trigger-click-jquery-not-working | |
$('a#swaswararedirectlink')[0].click(); |
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 | |
if(isset($_SERVER['HTTP_USER_AGENT'])){ | |
$agent = $_SERVER['HTTP_USER_AGENT']; | |
} | |
if (strlen(strstr($agent,"Chrome")) > 0) { | |
echo '<style type="text/css">#element{top:1px;}</style>'; | |
} | |
// 'firefox', etc. |
NewerOlder