Example #1
0
function y2f($amount)
{
    if (is_numeric($amount)) {
        if ($amount < 0) {
            echo "输入不能为负数";
            return;
        }
        echo $amount . "元 == " . $amount * 100 . '分';
    } else {
        echo $amount . '不是可转换的数字';
    }
}
// third
$email = "xxx mail";
try {
    $out = SplitEmailAddress($email);
    print_r(array_values($out));
} catch (Exception $e) {
}
function SplitEmailAddress($str)
{
    $tmp = explode("@", $str);
    isset($tmp[0]) ? $value["user"] = $tmp[0] : ($value["user"] = '');
    isset($tmp[1]) ? $value["domain"] = $tmp[1] : ($value["user"] = '');
    if ($value["user"] === '' || $value["domain"] === '') {
        echo "格式错误";
        //return;
        throw new Exception("格式错误");
    }
    return $value;
}
Example #2
0
<?php

//phpinfo();
function microtime_float()
{
    list($usec, $sec) = explode(" ", microtime());
    return (double) $usec + (double) $sec;
}
function SplitEmailAddress($email)
{
    return explode("@", $email);
}
echo "<h4>SplitEmailAddress</h4>";
$userdomain = SplitEmailAddress("*****@*****.**");
echo $userdomain[0] . " @ " . $userdomain[1] . "<br />";
/*
function GeneratePassword($len, $str)
{
	if ($len < 0 or strlen($str) <= 0)
		return null;
	$max = strlen($str) - 1;
	$ret = "";
	for ($i = 0; $i < $len; $i++)
		$ret .= $str[rand(0, $max)];
	return $ret;
}
*/
function GeneratePassword($len, $str)
{
    /*if ($len < 0 or strlen($str) <= 0)
    		return null;