本文整理汇总了PHP中either函数的典型用法代码示例。如果您正苦于以下问题:PHP either函数的具体用法?PHP either怎么用?PHP either使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了either函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: kdmail
function kdmail($f)
{
$this->load('lib/phpmailer/class.phpmailer');
$mail = new PHPMailer();
//$body = $mail->getFile(ROOT.'index.php');
//$body = eregi_replace("[\]",'',$body);
$mail->IsSendmail();
// telling the class to use SendMail transport
$mail->From = $f["from"];
$mail->FromName = either($f["fromname"], "noticer");
$mail->Subject = either($f["subject"], "hello");
//$mail->AltBody = either($f["altbody"], "To view the message, please use an HTML compatible email viewer!"); // optional, comment out and test
$mail->AltBody = either($f["msg"], "To view the message, please use an HTML compatible email viewer!");
// optional, comment out and test
if ($f["embedimg"]) {
foreach ($f["embedimg"] as $i) {
//$mail->AddEmbeddedImage(ROOT."public/images/logo7.png","logo","logo7.png");
$mail->AddEmbeddedImage($i[0], $i[1], $i[2]);
}
}
if ($f["msgfile"]) {
$body = $mail->getFile($f["msgfile"]);
$body = eregi_replace("[\\]", '', $body);
if ($f["type"] == "text") {
$mail->IsHTML(false);
$mail->Body = $body;
} else {
$mail->MsgHTML($body);
//."<br><img src= \"cid:logo\">");
}
} else {
if ($f["type"] == "text") {
$mail->IsHTML(false);
$mail->Body = $f["msg"];
} else {
$mail->MsgHTML($f["msg"]);
//."<br><img src= \"cid:logo\">");
}
}
if (preg_match('/\\,/', $f["to"])) {
$emails = explode(",", $f["to"]);
foreach ($emails as $i) {
$mail->AddAddress($i, $f["toname"]);
}
} else {
$mail->AddAddress($f["to"], $f["toname"]);
}
$mail->AddBCC($this->config["site"]["mail"], "bcc");
if ($f["files"]) {
foreach ($f["files"] as $i) {
$mail->AddAttachment($i);
// attachment
}
}
if (!$mail->Send()) {
return "Mailer Error: " . $mail->ErrorInfo;
} else {
return "Message sent!";
}
}
示例2: index
function index()
{
$dsn = array();
$this->sv("rooturl", preg_replace('/&t=.*/', '', $_SERVER['REQUEST_URI']));
if (f('submit')) {
$dsn['dbHost'] = either(f("host"), "db4free.net");
$dsn['port'] = either(f("port"), 3306);
$dsn['dbHost'] .= ":" . $dsn['port'];
$dsn['dbName'] = either(f("db"), "greedisok");
$dsn['dbUser'] = either(f("user"), "greedisok");
$dsn['dbPswd'] = either(f("pass"), 'greedisok');
$dsn["charset"] = "";
include_once ROOT . "lib/vip/DBUtil.php";
$db = new DB($dsn);
include_once ROOT . "app/main/model.php";
$modelobj = new model($db);
$this->sv("dsn", $dsn);
try {
$this->sv("table_list", $modelobj->table_names());
$table = f('t');
if ($table) {
$modelobj->change_table($table);
$table_detail = $modelobj->detail();
$this->sv("table_detail", $table_detail);
}
} catch (Exception $e) {
$this->sv("info", $e->getMessage());
}
}
}
示例3: array_to_multibulk
public static function array_to_multibulk($array)
{
$multi = array();
foreach ($array as $key => $val) {
array_push($multi, $key, either($val, ''));
}
return $multi;
}
示例4: __construct
public function __construct($id)
{
$this->id = either($id, uniqid());
$this->exists = false;
$data = Util::multibulk_to_array(Redis::hgetall($this->key()));
foreach ($data as $key => $val) {
$this->{$key} = json_decode($val, true);
}
$this->exists = count($data) > 0;
}
示例5: __invoke
function __invoke(ServerRequestInterface $request, ResponseInterface $response, callable $next)
{
// Note: the following change to the Request is router-specific and it's not required by other middleware.
// Only the router uses a mutating requestTarget to handle sub-routes.
// TODO: route using UriInterface and do not change requestTarget.
/** @var ServerRequestInterface $request */
$request = $request->withRequestTarget(either($request->getAttribute('virtualUri'), '.'));
//----------
return parent::__invoke($request, $response, $next);
}
示例6: compile
private function compile(array $tokens)
{
$cg = (object) ['ts' => TokenStream::fromSlice($tokens), 'parsers' => []];
traverse(rtoken('/^(T_\\w+)·(\\w+)$/')->onCommit(function (Ast $result) use($cg) {
$token = $result->token();
$id = $this->lookupCapture($token);
$type = $this->lookupTokenType($token);
$cg->parsers[] = token($type)->as($id);
}), ($parser = chain(rtoken('/^·\\w+$/')->as('type'), token('('), optional(ls(either(future($parser)->as('parser'), chain(token(T_FUNCTION), parentheses()->as('args'), braces()->as('body'))->as('function'), string()->as('string'), rtoken('/^T_\\w+·\\w+$/')->as('token'), rtoken('/^T_\\w+$/')->as('constant'), rtoken('/^·this$/')->as('this'), label()->as('label'))->as('parser'), token(',')))->as('args'), commit(token(')')), optional(rtoken('/^·\\w+$/')->as('label'), null)))->onCommit(function (Ast $result) use($cg) {
$cg->parsers[] = $this->compileParser($result->type, $result->args, $result->label);
}), $this->layer('{', '}', braces(), $cg), $this->layer('[', ']', brackets(), $cg), $this->layer('(', ')', parentheses(), $cg), rtoken('/^···(\\w+)$/')->onCommit(function (Ast $result) use($cg) {
$id = $this->lookupCapture($result->token());
$cg->parsers[] = layer()->as($id);
}), token(T_STRING, '·')->onCommit(function (Ast $result) use($cg) {
$offset = \count($cg->parsers);
if (0 !== $this->dominance || 0 === $offset) {
$this->fail(self::E_BAD_DOMINANCE, $offset, $result->token()->line());
}
$this->dominance = $offset;
}), rtoken('/·/')->onCommit(function (Ast $result) {
$token = $result->token();
$this->fail(self::E_BAD_CAPTURE, $token, $token->line());
}), any()->onCommit(function (Ast $result) use($cg) {
$cg->parsers[] = token($result->token());
}))->parse($cg->ts);
// check if macro dominance '·' is last token
if ($this->dominance === \count($cg->parsers)) {
$this->fail(self::E_BAD_DOMINANCE, $this->dominance, $cg->ts->last()->line());
}
$this->specificity = \count($cg->parsers);
if ($this->specificity > 1) {
if (0 === $this->dominance) {
$pattern = chain(...$cg->parsers);
} else {
/*
dominat macros are partially wrapped in commit()s and dominance
is the offset used as the 'event horizon' point... once the entry
point is matched, there is no way back and a parser error arises
*/
$prefix = array_slice($cg->parsers, 0, $this->dominance);
$suffix = array_slice($cg->parsers, $this->dominance);
$pattern = chain(...array_merge($prefix, array_map(commit::class, $suffix)));
}
} else {
/*
micro optimization to save one function call for every token on the subject
token stream whenever the macro pattern consists of a single parser
*/
$pattern = $cg->parsers[0];
}
return $pattern;
}
示例7: hygienize
function hygienize(TokenStream $ts, string $scope) : TokenStream
{
$ts->reset();
traverse(either(chain(token(T_STRING, '·unsafe'), parentheses()), either(token(T_VARIABLE)->as('target'), chain(identifier()->as('target'), token(':')), chain(token(T_GOTO), identifier()->as('target')))->onCommit(function (Ast $result) use($scope) {
(function () use($scope) {
if ((string) $this !== '$this') {
$this->value = (string) $this . '·' . $scope;
}
})->call($result->target);
}), any()))->parse($ts);
$ts->reset();
return $ts;
}
示例8: x2f
function x2f($params, $confirm = false, $procedure = "in_controller__form_mail")
{
$formG = new FormGeneratorList($_POST);
$file = get_w($params[0]);
$option = get_w($params[1]);
if (!$option) {
$option = "";
}
if (!$file or !file_exists(ROOT . "data/xml/{$file}.xml")) {
exit;
}
$xml = simplexml_load_file(ROOT . "data/xml/{$file}.xml");
//setting
$sendmail = $xml->sendmail == "yes";
$mailto = (string) $this->getOption($xml, "mailto", $option);
$formG->title = (string) $this->getOption($xml, "title", $option);
$formG->postTo = (string) $this->getOption($xml, "postback", $option);
$formG->md5seed = (string) $this->getOption($xml, "md5seed", "");
if ((string) $this->getOption($xml, "confirm", "") == "yes") {
$confirm = true;
}
$form = $xml->form;
$counti = 1;
foreach ($form->field as $field) {
$field = (array) $field;
$temp = array();
$temp["DISPLAY"] = $this->getOptionArr($field, "display", $option);
$temp["NAME"] = either($field["name"], "formelement_" . $counti++);
$html = $field["htmlgenerator"];
$classname = (string) $html->name;
if ($classname == "HiddenGenerator") {
$temp["HTML"] = new $classname(either((string) $html->param1, f($temp["NAME"])));
} else {
$temp["HTML"] = new $classname((string) $html->param1, (string) $html->param2, (string) $html->param3);
}
$tempvalid = array();
foreach ($field["valids"] as $validitem) {
$classname = (string) $validitem->name;
$tempvalid[] = new $classname((string) $validitem->param1, (string) $validitem->param2, (string) $validitem->param3);
}
$temp["VALID"] = $tempvalid;
$temp["ERROR"] = $this->getOptionArr($field, "error", $option);
$formG->addGenerator($temp);
}
$ra_param = array();
$ra_param["sendmail"] = $sendmail;
$ra_param["confirm"] = $confirm;
echo $this->processForm($formG, $procedure, $ra_param);
echo $this->htmlfooter();
exit;
}
示例9: preRender
protected function preRender()
{
$this->begin($this->containerTag);
$this->attr('id', either($this->props->containerId, $this->props->id));
$this->attr('class', enum(' ', rtrim($this->className, '_'), $this->props->class, $this->cssClassName, $this->props->disabled ? 'disabled' : null));
if (!empty($this->props->htmlAttrs)) {
echo ' ' . $this->props->htmlAttrs;
}
if ($this->htmlAttrs) {
foreach ($this->htmlAttrs as $k => $v) {
echo " {$k}=\"" . htmlspecialchars($v) . '"';
}
}
}
示例10: get_player_info
/**
* Returns the state of the player from the database,
* uses a user_id if one is present, otherwise
* defaults to the currently logged in player, but can act on any player
* if another username is passed in.
* @param $user user_id or username
* @param @password Unless true, wipe the password.
**/
function get_player_info($user = null, $password = false)
{
$sql = new DBAccess();
$player_data = null;
if (is_numeric($user)) {
$sel_player = "select * from players where player_id = '" . $user . "' limit 1";
} else {
$username = either($user, SESSION::is_set('username') ? SESSION::get('username') : null);
// Default to current session user.
$sel_player = "select * from players where uname = '" . sql($username) . "' limit 1";
}
$player_data = $sql->QueryRowAssoc($sel_player);
if (!$password) {
unset($player_data['pname']);
}
return $player_data;
}
示例11: index2
function index2($params)
{
$db = $this->fmodel('relation2');
$who = either(f('who'), 'root');
$this->sv('who', $who);
$type = f('type');
if ($type == 'add') {
$word2 = f('word2');
if ($word2) {
$word2_array = explode(",", $word2);
foreach ($word2_array as $j) {
$db->save(array('word1' => $this->process_words(f('word1')), 'word2' => $this->process_words($j), 'relation' => f('relation'), 'who' => $who));
}
}
$this->to_path('?who=' . $who . '&type=relation&word=' . urlencode($this->process_words(f('word1'))));
}
$all = $db->peeks(array('who' => $who));
$level = count($all);
$words = array();
foreach ($all as $i) {
$words[] = $i['word1'];
$words[] = $i['word2'];
}
$words = array_unique($words);
sort($words);
$this->sv('words', $words);
$this->sv('all', $all);
$this->sv('level', $this->levelstr($level));
if ($type == 'relation') {
$frwords = array();
$brwords = array();
$word = f('word');
foreach ($all as $i) {
if ($i['word1'] == $word) {
$frwords[] = array('id' => $i['id'], 'word' => $i['word2'], 'relation' => str_replace(' ', ' ', e($i['relation'])));
}
if ($i['word2'] == $word) {
$brwords[] = array('id' => $i['id'], 'word' => $i['word1'], 'relation' => str_replace(' ', ' ', e($i['relation'])));
}
}
$frwords = array_unique($frwords);
$brwords = array_unique($brwords);
$this->sv('frwords', $frwords);
$this->sv('brwords', $brwords);
}
}
示例12: hygienize
function hygienize(TokenStream $ts, array $context) : TokenStream
{
$ts->reset();
$cg = (object) ['node' => null, 'context' => $context, 'ts' => $ts];
$saveNode = function (Parser $parser) use($cg) {
return midrule(function ($ts) use($cg, $parser) {
$cg->node = $ts->index();
return $parser->parse($ts);
});
};
traverse(chain(token(T_STRING, '··unsafe'), either(parentheses(), braces())), either($saveNode(token(T_VARIABLE)), chain($saveNode(identifier()), token(':')), chain(token(T_GOTO), $saveNode(identifier())))->onCommit(function (Ast $result) use($cg) {
if (($t = $cg->node->token) && ($value = (string) $t) !== '$this') {
$cg->node->token = new Token($t->type(), "{$value}·{$cg->context['scope']}", $t->line());
}
}))->parse($ts);
$ts->reset();
return $ts;
}
示例13: render_avatar
/**
* Pull out the url for the player's avatar
**/
function render_avatar($player, $size = null)
{
// If the avatar_type is 0, return '';
if (!$player->vo || !$player->vo->avatar_type || !$player->vo->email) {
return '';
} else {
// Otherwise, user the player info for creating a gravatar.
$def = 'identicon';
// Default image or image class.
// other options: wavatar , monsterid
$email = $player->vo->email;
$avatar_type = $player->vo->avatar_type;
$base = "http://www.gravatar.com/avatar/";
$hash = md5(trim(strtolower($email)));
$no_gravatar = "d=" . urlencode($def);
$size = either($size, 80);
$rating = "r=x";
$res = $base . $hash . "?" . implode("&", array($no_gravatar, $size, $rating));
return $res;
}
}
示例14: __invoke
function __invoke(ServerRequestInterface $request, ResponseInterface $response, callable $next)
{
$path = either($request->getAttribute('virtualUri', '<i>not set</i>'), '<i>empty</i>');
$realPath = $request->getUri()->getPath();
return Http::response($response, "<br><br><table align=center cellspacing=20 style='text-align:left'>\n<tr><th>Virtual URL:<td><kbd>{$path}</kbd>\n<tr><th>URL path:<td><kbd>{$realPath}</kbd>\n</table>", 'text/html', 404);
}
示例15: in
$item = in('item');
$grammar = "";
$username = get_username();
$gold = either(getGold($username), 0);
$current_item_cost = 0;
$quantity = intval($in_quantity);
if (!$quantity || $quantity < 1) {
$quantity = 1;
} else {
if ($quantity > 1 && $item != "Shuriken") {
$grammar = "s";
}
}
$item_costs = array("Speed Scroll" => 225, "Fire Scroll" => 175, "Stealth Scroll" => 150, "Ice Scroll" => 125, "Shuriken" => 50);
if ($in_purchase == 1) {
$current_item_cost = either($item_costs[$item], 0);
$current_item_cost *= $quantity;
if ($current_item_cost > $gold) {
// Not enough gold.
$description .= "<p>\"The total comes to {$current_item_cost} gold,\" the shopkeeper tells you.</p>";
$description .= "<p>Unfortunately, you do not have that much gold.</p>";
} else {
// Has enough gold.
addItem($username, $item, $quantity);
$description .= "<p>The shopkeeper hands over {$quantity} " . $item . $grammar . ".</p>";
$description .= "<p>\"Will you be needing anything else today?\" he asks you as he puts your gold in a safe.</p>";
subtractGold($username, $current_item_cost);
}
} else {
// Default, before anything has been bought.
$description .= "<p>You enter the village shop and the shopkeeper greets you with a watchful eye.</p>";