📄 phpmkrfn.php
字号:
$frac_digits = $NumDigitsAfterDecimal;
// check $UseParensForNegativeNumbers
if ($UseParensForNegativeNumbers == -1) {
$n_sign_posn = 0;
if ($p_sign_posn == 0) {
if (DEFAULT_P_SIGN_POSN != 0)
$p_sign_posn = DEFAULT_P_SIGN_POSN;
else
$p_sign_posn = 3;
}
} elseif ($UseParensForNegativeNumbers == 0) {
if ($n_sign_posn == 0)
if (DEFAULT_P_SIGN_POSN != 0)
$n_sign_posn = DEFAULT_P_SIGN_POSN;
else
$n_sign_posn = 3;
}
// check $GroupDigits
if ($GroupDigits == -1) {
$mon_thousands_sep = DEFAULT_MON_THOUSANDS_SEP;
} elseif ($GroupDigits == 0) {
$mon_thousands_sep = "";
}
// start by formatting the unsigned number
$number = number_format(abs($amount),
$frac_digits,
$mon_decimal_point,
$mon_thousands_sep);
// check $IncludeLeadingDigit
if ($IncludeLeadingDigit == 0) {
if (substr($number, 0, 2) == "0.")
$number = substr($number, 1, strlen($number)-1);
}
if ($amount < 0) {
$sign = $negative_sign;
$key = $n_sign_posn;
} else {
$sign = $positive_sign;
$key = $p_sign_posn;
}
$formats = array(
'0' => '(%s)',
'1' => $sign . '%s',
'2' => $sign . '%s',
'3' => $sign . '%s',
'4' => $sign . '%s');
// lookup the key in the above array
return sprintf($formats[$key], $number);
}
// FormatPercent
/*
FormatPercent(Expression[,NumDigitsAfterDecimal [,IncludeLeadingDigit
[,UseParensForNegativeNumbers [,GroupDigits]]]])
NumDigitsAfterDecimal is the numeric value indicating how many places to the
right of the decimal are displayed
-1 Use Default
The IncludeLeadingDigit, UseParensForNegativeNumbers, and GroupDigits
arguments have the following settings:
-1 True
0 False
-2 Use Default
*/
function FormatPercent($amount, $NumDigitsAfterDecimal, $IncludeLeadingDigit, $UseParensForNegativeNumbers, $GroupDigits)
{
// export the values returned by localeconv into the local scope
if (function_exists("localeconv")) extract(localeconv());
// set defaults if locale is not set
if (empty($currency_symbol)) $currency_symbol = DEFAULT_CURRENCY_SYMBOL;
if (empty($mon_decimal_point)) $mon_decimal_point = DEFAULT_MON_DECIMAL_POINT;
if (empty($mon_thousands_sep)) $mon_thousands_sep = DEFAULT_MON_THOUSANDS_SEP;
if (empty($positive_sign)) $positive_sign = DEFAULT_POSITIVE_SIGN;
if (empty($negative_sign)) $negative_sign = DEFAULT_NEGATIVE_SIGN;
if (empty($frac_digits) || $frac_digits == CHAR_MAX) $frac_digits = DEFAULT_FRAC_DIGITS;
if (empty($p_cs_precedes) || $p_cs_precedes == CHAR_MAX) $p_cs_precedes = DEFAULT_P_CS_PRECEDES;
if (empty($p_sep_by_space) || $p_sep_by_space == CHAR_MAX) $p_sep_by_space = DEFAULT_P_SEP_BY_SPACE;
if (empty($n_cs_precedes) || $n_cs_precedes == CHAR_MAX) $n_cs_precedes = DEFAULT_N_CS_PRECEDES;
if (empty($n_sep_by_space) || $n_sep_by_space == CHAR_MAX) $n_sep_by_space = DEFAULT_N_SEP_BY_SPACE;
if (empty($p_sign_posn) || $p_sign_posn == CHAR_MAX) $p_sign_posn = DEFAULT_P_SIGN_POSN;
if (empty($n_sign_posn) || $n_sign_posn == CHAR_MAX) $n_sign_posn = DEFAULT_N_SIGN_POSN;
// check $NumDigitsAfterDecimal
if ($NumDigitsAfterDecimal > -1)
$frac_digits = $NumDigitsAfterDecimal;
// check $UseParensForNegativeNumbers
if ($UseParensForNegativeNumbers == -1) {
$n_sign_posn = 0;
if ($p_sign_posn == 0) {
if (DEFAULT_P_SIGN_POSN != 0)
$p_sign_posn = DEFAULT_P_SIGN_POSN;
else
$p_sign_posn = 3;
}
} elseif ($UseParensForNegativeNumbers == 0) {
if ($n_sign_posn == 0)
if (DEFAULT_P_SIGN_POSN != 0)
$n_sign_posn = DEFAULT_P_SIGN_POSN;
else
$n_sign_posn = 3;
}
// check $GroupDigits
if ($GroupDigits == -1) {
$mon_thousands_sep = DEFAULT_MON_THOUSANDS_SEP;
} elseif ($GroupDigits == 0) {
$mon_thousands_sep = "";
}
// start by formatting the unsigned number
$number = number_format(abs($amount)*100,
$frac_digits,
$mon_decimal_point,
$mon_thousands_sep);
// check $IncludeLeadingDigit
if ($IncludeLeadingDigit == 0) {
if (substr($number, 0, 2) == "0.")
$number = substr($number, 1, strlen($number)-1);
}
if ($amount < 0) {
$sign = $negative_sign;
$key = $n_sign_posn;
} else {
$sign = $positive_sign;
$key = $p_sign_posn;
}
$formats = array(
'0' => '(%s%%)',
'1' => $sign . '%s%%',
'2' => $sign . '%s%%',
'3' => $sign . '%s%%',
'4' => $sign . '%s%%');
// lookup the key in the above array
return sprintf($formats[$key], $number);
}
function ewUploadPath($parm)
{
global $HTTP_SERVER_VARS;
global $HTTP_ENV_VARS;
$delim = (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') ? "\\" : "/";
if ($parm == 0) {
$ewUploadPath = "";
} else {
$ewUploadPath = ewScriptFileName();
$ewUploadPath = str_replace("\\\\","\\",dirname($ewUploadPath));
}
// Customize the upload path here
// Check the last delimiter
if ($parm == 0) {
if ($ewUploadPath <> "" && substr($ewUploadPath, -1) <> "/") { $ewUploadPath .= "/"; }
} else {
if (substr($ewUploadPath, -1) <> $delim) { $ewUploadPath .= $delim; }
}
return $ewUploadPath;
}
function ewUploadFileName($sFileName)
{
// Amend your logic here
$sOutFileName = $sFileName;
// Return computed output file name
return $sOutFileName;
}
function ewScriptFileName() {
global $HTTP_SERVER_VARS;
global $HTTP_ENV_VARS;
$sScriptFileName = @$HTTP_ENV_VARS["SCRIPT_FILENAME"];
if (empty($sScriptFileName)) {$sScriptFileName = @$HTTP_SERVER_VARS["SCRIPT_FILENAME"];}
if (empty($sScriptFileName)) {$sScriptFileName = @$HTTP_ENV_VARS["PATH_TRANSLATED"];}
if (empty($sScriptFileName)) {$sScriptFileName = @$HTTP_SERVER_VARS["PATH_TRANSLATED"];}
if (empty($sScriptFileName)) {$sScriptFileName = @$HTTP_ENV_VARS["ORIG_PATH_TRANSLATED"];}
if (empty($sScriptFileName)) {$sScriptFileName = @$HTTP_SERVER_VARS["ORIG_PATH_TRANSLATED"];}
if (empty($sScriptFileName)) {die("Path of script not found. You can use phpinfo() to find the correct environment/server variable on your server and modify the function ewScriptFileName() in phpmkrfn.php. The variable should return the full path of the script.");}
return $sScriptFileName;
}
?>
<?php
// Function to Load Email Content from input file name
// - Content Loaded to the following variables
// - Subject: sEmailSubject
// - From: sEmailFrom
// - To: sEmailTo
// - Cc: sEmailCc
// - Bcc: sEmailBcc
// - Format: sEmailFormat
// - Content: sEmailContent
//
function LoadEmail($fn)
{
global $sEmailSubject;
global $sEmailFrom;
global $sEmailTo;
global $sEmailCc;
global $sEmailBcc;
global $sEmailFormat;
global $sEmailContent;
$sWrk = LoadTxt($fn); // Load text file content
if ($sWrk <> "") {
// Locate Header & Mail Content
if (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') {
$i = strpos($sWrk, "\r\n\r\n");
}else {
$i = strpos($sWrk, "\n\n");
if ($i === false) $i = strpos($sWrk, "\r\n\r\n");
}
if ($i > 0) {
$sHeader = substr($sWrk, 0, $i);
$sEmailContent = trim(substr($sWrk, $i, strlen($sWrk)));
if (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') {
$arrHeader = split("\r\n",$sHeader);
} else {
$arrHeader = split("\n",$sHeader);
}
for ($j = 0; $j < count($arrHeader); $j++)
{
$i = strpos($arrHeader[$j], ":");
if ($i > 0) {
$sName = trim(substr($arrHeader[$j], 0, $i));
$sValue = trim(substr($arrHeader[$j], $i+1, strlen($arrHeader[$j])));
switch (strtolower($sName))
{
case "subject": $sEmailSubject = $sValue;
break;
case "from": $sEmailFrom = $sValue;
break;
case "to": $sEmailTo = $sValue;
break;
case "cc": $sEmailCc = $sValue;
break;
case "bcc": $sEmailBcc = $sValue;
break;
case "format": $sEmailFormat = $sValue;
break;
}
}
}
}
}
}
// Function to Load a Text File
function LoadTxt($fn)
{
$filepath = str_replace("\\\\","\\",dirname(ewScriptFileName()));
// Get text file content
if (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') {
$filepath .= "\\" . $fn;
} else {
$filepath .= "/" . $fn;
}
$fobj = fopen ($filepath , "r");
return fread ($fobj, filesize ($filepath));
}
// Function to Send out Email
function Send_Email($sFrEmail, $sToEmail, $sCcEmail, $sBccEmail, $sSubject, $sMail, $sFormat)
{
/* recipients */
$to = $sToEmail;
/* subject */
$subject = $sSubject;
$headers = "";
if ($sFormat == "html") {
$content_type = "text/html";
} else {
$content_type = "text/plain";
}
$headers = "Content-type: " . $content_type . "\r\n";
$message = $sMail;
/* additional headers */
$headers .= "From: " . $sFrEmail . "\r\n";
if ($sCcEmail <> "") {
$headers .= "Cc: " . $sCcEmail . "\r\n";
}
if ($sBccEmail <>"") {
$headers .= "Bcc: " . $sBccEmail . "\r\n";
}
/* and now mail it */
if (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') {
ini_set("SMTP","localhost");
ini_set("smtp_port","25");
}
ini_set("sendmail_from",$sFrEmail);
mail($to, $subject, $message, $headers);
}
?>
<?php
// Function to generate Value Separator based on current row count
// rowcnt - zero based row count
//
function ValueSeparator($rowcnt)
{
return ", ";
}
// Function to generate View Option Separator based on current row count (Multi-Select / CheckBox)
// rowcnt - zero based row count
//
function ViewOptionSeparator($rowcnt)
{
return ", ";
}
// Function to generate Edit Option Separator based on current row count (Radio / CheckBox)
// rowcnt - zero based row count
//
function EditOptionSeparator($rowcnt)
{
return " ";
}
// Function to truncate Memo Field based on specified length, string truncated to nearest space or CrLf
//
function TruncateMemo($str, $ln)
{
if (strlen($str) > 0 && strlen($str) > $ln) {
$k = 0;
while ($k >= 0 && $k < strlen($str)){
$i = strpos($str, " ", $k);
$j = strpos($str,chr(10), $k);
if ($i === false && $j === false) { // Not able to truncate
return $str;
} else {
// Get nearest space or CrLf
if ($i > 0 && $j > 0) {
if ($i < $j) {
$k = $i;
}else{
$k = $j;
}
}elseif ($i > 0) {
$k = $i;
}elseif ($j > 0) {
$k = $j;
}
// Get truncated text
if ($k >= $ln) {
return substr($str, 0, $k) . "...";
} else {
$k ++;
}
}
}
} else {
return $str;
}
}
?>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -