本文整理汇总了PHP中matches函数的典型用法代码示例。如果您正苦于以下问题:PHP matches函数的具体用法?PHP matches怎么用?PHP matches使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了matches函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: LatestTotals
public function LatestTotals($id, $byType = FALSE)
{
$ordering = ' ';
if ($byType === FALSE) {
$result = $this->Select('Uploader = ' . $id . $ordering);
} else {
if (matches($byType, 'stl')) {
$result = $this->Select('Type LIKE "%stl%"' . $ordering);
} else {
if (matches($byType, 'images')) {
$result = $this->Select('Type LIKE "image%"' . $ordering);
} else {
if (matches($byType, 'configs')) {
$result = $this->Select('Type LIKE "text/plain"' . $ordering);
} else {
if (matches($byType, 'wav')) {
$result = $this->Select('Type LIKE "audio/wav"' . $ordering);
} else {
if (matches($byType, 'flac')) {
$result = $this->Select('Type LIKE "audio/flac"' . $ordering);
} else {
if (matches($byType, 'f3xb')) {
$result = $this->Select('Type LIKE "font/3d-extruded-binary"' . $ordering);
} else {
$result = $this->Select('ORDER BY ID DESC');
}
}
}
}
}
}
}
return false_or_null($result) ? 0 : count($result);
}
示例2: __construct
/**
* @constructor
*
* @param {array} $rules Redirect rules
* @param {callable|string} $rules[][source] Regex, plain string startsWith() or callback matcher func,
* @param {string} $rules[][target] String for redirection, can use backreference on regex,
* @param {?int} $rules[][options] Redirection $options, or internal by default,
* @param {?string} $options[source] Base path to match against requests, defaults to root.
* @param {string|callable} $options[target] Redirects to a static target, or function($request) returns a string;
*/
public function __construct($rules)
{
// rewrite all URLs
if (is_string($rules)) {
$rules = array('*' => $rules);
}
$rules = util::wrapAssoc($rules);
$this->rules = array_reduce($rules, function ($result, $rule) {
$rule = array_select($rule, array('source', 'target', 'options'));
// note: make sure source is callback
if (is_string($rule['source'])) {
// regex
if (@preg_match($rule['source'], null) !== false) {
$rule['source'] = matches($rule['source']);
if (is_string($rule['target'])) {
$rule['target'] = compose(invokes('uri', array('path')), replaces($rule['source'], $rule['target']));
}
} else {
if (!is_callable($rule['source'])) {
$rule['source'] = startsWith($rule['source']);
if (is_string($rule['target'])) {
$rule['target'] = compose(invokes('uri', array('path')), replaces('/^' . preg_quote($rule['source']) . '/', $rule['target']));
}
}
}
}
if (!is_callable($rule['source'])) {
throw new InvalidArgumentException('Source must be string, regex or callable.');
}
$result[] = $rule;
return $result;
}, array());
}
示例3: authenticate
function authenticate($users, $username, $password)
{
for ($i = 0; $i < count($users); $i++) {
if (matches($users[$i]->username, $username) && matches($users[$i]->password, $password)) {
return true;
}
}
return false;
}
示例4: where
function where($collection, $properties)
{
$matches = matches($properties);
$results = array();
foreach ($collection as $key => $value) {
if ($matches($value)) {
$results[$key] = $value;
}
}
return $results;
}
示例5: remove
public static function remove($haystack, $needle, $delim = ',')
{
$words = words($haystack, $delim);
$out = "";
$last = count($words);
foreach ($words as $word) {
if (matches($needle, $word)) {
continue;
} else {
$out .= $word . $delim;
}
}
return rtrim($out, $delim);
}
示例6: byTableID
public function byTableID($t, $id)
{
$results = array();
$mods = $this->Select('What LIKE "%' . $t . '%" AND What LIKE "%' . $id . '%" ORDER BY Timestamp DESC');
foreach ($mods as $possible) {
$json = json_decode($possible['What'], true);
foreach ($json as $dataset) {
foreach ($dataset as $table => $change) {
if (intval($change['I']) === intval($id) && matches($table, $t)) {
$results[] = $possible;
}
}
}
}
return $results;
}
示例7: check
function check($str)
{
$len = strlen($str);
$stack = array();
for ($i = 0; $i < $len; $i++) {
$theChar = $str[$i];
if (is_open($theChar)) {
$stack[] = $theChar;
} else {
$matching = array_pop($stack);
if (!matches($matching, $theChar)) {
return false;
}
}
}
return count($stack) == 0;
}
示例8: process_first_form
function process_first_form()
{
global $errors;
$required_fields = array("firstname", "lastname", "email", "password", "passwordagain");
validate_presences($required_fields);
// Limits provided should correspond to the limits set in the sql database
$fields_with_max_lengths = array("firstname" => 20, "lastname" => 20, "email" => 50, "password" => 20);
validate_max_lengths($fields_with_max_lengths);
// Check that password == passwordagain
matches($_POST['password'], $_POST['passwordagain']);
// check that email has not already been used
validate_email($_POST['email']);
// check that role was checked and value is acceptable
validate_role($_POST['role-check']);
if (empty($errors)) {
// Success outcome:
// Store values entered and wait for user to submit current form
// This uses the current session, session should be
// destroyed once the registration process ends :NT
$_SESSION['firstname'] = $_POST['firstname'];
$_SESSION["lastname"] = $_POST['lastname'];
$_SESSION["email"] = $_POST['email'];
$_SESSION["password"] = $_POST['password'];
$_SESSION["role"] = $_POST['role-check'];
$_SESSION['user_details'] = 1;
//confirm successful outcome in session
} else {
// Failure outcome: one or more elements in $errors
// Either display messages from $errors here in address.php or
// signup.php
if (!isset($_POST['test'])) {
//Store what is needed in the session
$_SESSION['firstname'] = $_POST['firstname'];
$_SESSION["lastname"] = $_POST['lastname'];
$_SESSION["email"] = $_POST['email'];
$_SESSION['errors'] = $errors;
redirect_to("signup.php");
}
}
}
示例9: ajax_js_help_get_help
function ajax_js_help_get_help($opt_name, $tools)
{
$str = $tools->get_hm_strings();
$opt_name2 = $tools->display_safe($opt_name);
$opt_name3 = $tools->display_safe(decode_unicode_url($opt_name), 'UTF-8');
$opt_name4 = decode_unicode_url($opt_name);
$trans = array_keys($tools->str);
$res = '';
foreach ($trans as $i) {
if (strstr($i, 'plugin')) {
continue;
}
$v = $str[$i];
if (matches($opt_name, $v) || matches($opt_name2, $v) || matches($opt_name3, $v)) {
$res = sprintf($tools->str[$i], '<b>' . $v . '</b>');
break;
}
}
if (!$res) {
$str_list = array();
$plugin_vals = $tools->get_from_global_store('help_strings');
foreach ($plugin_vals as $plugin => $vals) {
if (isset($tools->str[$plugin . '_plugin'])) {
foreach ($vals as $i => $v) {
if (matches($opt_name, $v) || matches($opt_name2, $v) || matches($opt_name3, $v) || matches($opt_name4, $v)) {
if (isset($tools->str[$plugin . '_plugin'][$i])) {
$res = sprintf($tools->str[$plugin . '_plugin'][$i], '<b>' . $v . '</b>');
}
}
}
}
}
if (!$res) {
$res = 'Could not find that setting!';
}
}
return $res;
}
示例10: Modified
function Modified($what, $message = '')
{
// plog('Modified('.$what.','.$message.')');
global $auth, $database;
$m = new Modification($database);
$mods = $m->Select('r_Auth = ' . $auth['ID'] . ' ORDER BY Timestamp DESC LIMIT 50');
$now = strtotime('now');
$what_json = json_encode($what);
// Messages are not saved if they are a duplicate of a recent event.
if (!false_or_null($mods)) {
foreach ($mods as $a) {
if ($now - intval($a['Timestamp']) > 30) {
continue;
}
if (strlen($a['What']) === strlen($what_json) && matches($what_json, $a['What']) && matches($message, $a['Message'])) {
/*plog("Modified matched previous message");*/
return FALSE;
}
}
}
RemoveOldModifications();
return $m->Insert(array('r_Auth' => $auth['ID'], 'What' => $what_json, 'Message' => $message, 'Timestamp' => $now));
}
示例11: key_matcher
/**
* Returns matcher closure by $pattern
*
* @param array $pattern
*
* @return \Closure
*
* @see https://github.com/ptrofimov/matchmaker - ultra-fresh PHP matching functions
* @author Petr Trofimov <petrofimov@yandex.ru>
*/
function key_matcher(array $pattern)
{
$keys = [];
foreach ($pattern as $k => $v) {
$chars = ['?' => [0, 1], '*' => [0, PHP_INT_MAX], '!' => [1, 1]];
if (isset($chars[$last = substr($k, -1)])) {
$keys[$k = substr($k, 0, -1)] = $chars[$last];
} elseif ($last == '}') {
list($k, $range) = explode('{', $k);
$range = explode(',', rtrim($range, '}'));
$keys[$k] = count($range) == 1 ? [$range[0], $range[0]] : [$range[0] === '' ? 0 : $range[0], $range[1] === '' ? PHP_INT_MAX : $range[1]];
} else {
$keys[$k] = $chars[$k[0] == ':' ? '*' : '!'];
}
array_push($keys[$k], $v, 0);
}
return function ($key = null, $value = null) use(&$keys) {
if (is_null($key)) {
foreach ($keys as $count) {
if ($count[3] < $count[0] || $count[3] > $count[1]) {
return false;
}
}
} else {
foreach ($keys as $k => &$count) {
if (matcher($key, $k)) {
if (!matches($value, $count[2])) {
return false;
}
$count[3]++;
}
}
}
return true;
};
}
示例12: foreach
global $database;
foreach ($modes as $mode) {
switch ($mode) {
default:
Page::Redirect('dash?nosuchform');
break;
case 1:
if (!Session::logged_in()) {
Page::Redirect('login');
}
global $auth;
$old = AJAX::Value($ajax, 'changeMyPassword', 'password', 'old');
$change = AJAX::Value($ajax, 'changeMyPassword', 'password', 'new');
$repeat = AJAX::Value($ajax, 'changeMyPassword', 'password', 'confirm');
if (strlen($auth['password']) === 0 || Auth::PasswordMatches(ourcrypt($old), $auth['password'])) {
if (matches($change, $repeat, TRUE)) {
global $auth_model;
$auth_model->Update(array('password' => ourcrypt($change), 'password_expiry' => strtotime('+1 year')), array('ID' => $auth['ID']));
echo js('Notifier.success("Password changed!");');
die;
} else {
echo js('Notifier.error("Passwords did not match.");');
die;
}
} else {
echo js('Notifier.error("You got your password wrong.","Logging you out.");
setTimeout( function() { window.location="logout"; }, 2000 );');
die;
}
break;
}
示例13: chdir
}
chdir($cwd);
unset($cwd);
// restore working directory
return;
// then exits.
}
}
unset($res);
}
unset($fragments);
}
// static view assets redirection
// note; composer.json demands the name to be of format "vendor/name".
return @".private/modules/{$instance->name}/views/{$matches['2']}";
}), array('source' => '/^\\/faye\\/client.js/', 'target' => array('uri' => array('port' => 8080, 'path' => '/client.js'), 'options' => array('status' => 307))), array('source' => funcAnd(matches('/^(?!(?:\\/assets|\\/service))/'), compose('not', pushesArg('pathinfo', PATHINFO_EXTENSION))), 'target' => '/'))), 65);
// Web Services
$resolver->registerResolver(new resolvers\WebServiceResolver(array('prefix' => conf::get('web::resolvers.service.prefix', '/service'))), 60);
// Post Processers
$resolver->registerResolver(new resolvers\InvokerPostProcessor(array('invokes' => 'invokes', 'unwraps' => 'core\\Utility::unwrapAssoc')), 50);
// Template resolver
// $templateResolver = new resolvers\TemplateResolver(array(
// 'render' => function($path) {
// static $mustache;
// if ( !$mustache ) {
// $mustache = new Mustache_Engine();
// }
// $resource = util::getResourceContext();
// return $mustache->render(file_get_contents($path), $resource);
// }
// , 'extensions' => 'mustache html'
示例14: LockMechanism
function LockMechanism(&$p, $table, $id)
{
$locked = LockCheck($table, $id);
if (matches($table, "Modified")) {
return;
}
$p->HTML('<div class="padlockarea"><span id="padlock" class="redbutton">' . '<span id="padlockface" class=""></span>' . '</span>' . '<span id="padlockmsg"></span>' . '</div>');
$p->JQ('
$.ajax({
url:"ajax.skeleton.key",
data:{S:1,T:"' . $table . '",I:' . $id . '},
dataType:"html",
success:function(d){
page_lock_status=parseInt(d) == 1 ? true : false;
if ( page_lock_status ) {
$("#padlockface").removeClass("fi-unlock");
$("#padlockface").addClass("fi-lock");
$("#padlockmsg").get(0).innerHTML=" locked";
} else {
$("#padlockface").removeClass("fi-lock");
$("#padlockface").addClass("fi-unlock");
$("#padlockmsg").get(0).innerHTML=" ";
}
}
});
var page_lock_status=' . ($locked ? 'true' : 'false') . ';
$("#padlock").on("click",function(e){
$.ajax({
url:"ajax.skeleton.key",
data:{T:"' . $table . '",I:' . $id . '},
dataType:"html",
success:function(d){
page_lock_status=parseInt(d) == 1 ? true : false;
if ( page_lock_status ) {
$("#padlockface").removeClass("fi-unlock");
$("#padlockface").addClass("fi-lock");
$("#padlockmsg").get(0).innerHTML=" locked";
} else {
$("#padlockface").removeClass("fi-lock");
$("#padlockface").addClass("fi-unlock");
$("#padlockmsg").get(0).innerHTML=" ";
}
}
});
setInterval(function(){
$.ajax({
url:"ajax.skeleton.key",
data:{S:1,T:"' . $table . '",I:' . $id . '},
dataType:"html",
success:function(d){
page_lock_status=parseInt(d) == 1 ? true : false;
if ( page_lock_status ) {
$("#padlockface").removeClass("fi-unlock");
$("#padlockface").addClass("fi-lock");
$("#padlockmsg").get(0).innerHTML=" locked";
} else {
$("#padlockface").removeClass("fi-lock");
$("#padlockface").addClass("fi-unlock");
$("#padlockmsg").get(0).innerHTML=" ";
}
}
});
}, 15000 );
});
');
}
示例15: Load
public function Load($ff, $addendum, $signal)
{
if (!isfile($ff, 'forms/')) {
return;
}
$file = file_get_contents('forms/' . $ff);
$data = new HDataStream($file);
$data = $data->toArray();
$settings = array();
$settings['insert'] = array();
$settings['hidden'] = array();
$settings['text'] = array();
$settings['multiline'] = array();
$settings['slider'] = array();
$settings['date'] = array();
$settings['select'] = array();
$settings['radio'] = array();
$settings['submit'] = array();
$settings['list'] = array();
$settings['name'] = 'form';
$settings['action'] = 'ajax.post.php';
if (!is_null($addendum) && is_array($addendum)) {
foreach ($addendum as $add => $val) {
$settings[$add] = $val;
}
}
if (isset($settings['dbid'])) {
$this->dbid = $settings['dbid'];
}
$t = count($data);
$o = 0;
for ($i = 0; $i < $t; $i++) {
$setting = $data[$i + 1];
if (matches($data[$i], "text")) {
$settings['text'][$o++] = HDataStream::asKV($setting);
} else {
if (matches($data[$i], "hidden")) {
$settings['hidden'][$o++] = HDataStream::asKV($setting);
} else {
if (matches($data[$i], "multiline") || matches($data[$i], "textarea")) {
$settings['multiline'][$o++] = HDataStream::asKV($setting);
} else {
if (matches($data[$i], "slider")) {
$settings['slider'][$o++] = HDataStream::asKV($setting);
} else {
if (matches($data[$i], "date")) {
$settings['date'][$o++] = HDataStream::asKV($setting);
} else {
if (matches($data[$i], "select")) {
$settings['select'][$o++] = HDataStream::asKV($setting);
} else {
if (matches($data[$i], "list")) {
$settings['list'][$o++] = HDataStream::asKV($setting);
} else {
if (matches($data[$i], "radio")) {
$settings['radio'][$o++] = HDataStream::asKV($setting);
} else {
if (matches($data[$i], "insert")) {
$settings['insert'][$o++] = HDataStream::asKV($setting);
} else {
if (matches($data[$i], "submit")) {
$settings['submit'][$o++] = HDataStream::asKV($setting);
} else {
$settings[$data[$i]] = $setting;
}
}
}
}
}
}
}
}
}
}
$i++;
}
$this->form = new FormHelper($settings['name'], $settings['action'], $this->dbid, $signal);
for ($i = 0; $i < $o; $i++) {
if (isset($settings['radio'][$i])) {
$e = $settings['radio'][$i];
$e['html'] = HDataStream::asKV($e['html']);
$e['options'] = HDataStream::asKV($e['options']);
$element = new FormRadio($e, TRUE);
if (!is_null($this->data) && isset($e['data']) && isset($this->data[$e['data']])) {
$element->Set($this->data[$e['data']]);
}
$element->_Init($element->settings);
$this->form->Add($element);
} else {
if (isset($settings['select'][$i])) {
$e = $settings['select'][$i];
$e['html'] = HDataStream::asKV($e['html']);
$e['options'] = HDataStream::asKV($e['options']);
$element = new FormSelect($e, TRUE);
if (!is_null($this->data) && isset($e['data']) && isset($this->data[$e['data']])) {
$element->Set($this->data[$e['data']]);
}
$element->_Init($element->settings);
$this->form->Add($element);
} else {
//.........这里部分代码省略.........