本文整理汇总了PHP中preg_filter函数的典型用法代码示例。如果您正苦于以下问题:PHP preg_filter函数的具体用法?PHP preg_filter怎么用?PHP preg_filter使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了preg_filter函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: parse
/**
*
* Parse the file in 1 go
*
*/
function parse()
{
$pattern = array('/^Name\\s*:\\s*(.*)$/i', '/^Version\\s*:\\s*(.*)$/i', '/^Release\\s*:\\s*(\\S*)(%\\{\\?dist\\}).*$/', '/^Release\\s*:\\s*(\\S*)$/', '/^Summary\\s*:\\s*(.*)$/i', '/^License\\s*:\\s*(.*)$/i', '/^URL\\s*:\\s*(.*)$/i', '/^Epoch\\s*:\\s*(.*)/i', '/^Group\\s*:\\s*(.*)$/i', '/^%define\\s*(\\S*)\\s*(\\S*)\\s*$/i', '/^%description\\s*$/i', '/^%description\\s*(.*)$/i', '/^%description\\s*:(.*)$/', '/%package\\s*(.*)$/i', '/^Requires\\s*:(.*)$/i', '/^Obsoletes\\s*:(.*)$/i', '/^Conflicts\\s*:(.*)$/i', '/^Provides\\s*:(.*)$/i', '/^BuildRequires\\s*:(.*)$/i', '/^%(\\S+)\\s*(.*)$/i', '/^.*$/');
$replace = array('name: $1', 'version: $1', 'release: $1' . $this->distribution, 'release: $1', 'summary: $1', 'license: $1', 'url: $1', 'epoch: $1', 'group: $1', '$1: $2', 'description: $1', 'description: $1', 'description: $1', 'package: $1', 'depends: $1', 'obsoletes: $1', 'conflicts: $1', 'provides: $1', 'buildDepends: $1', '$1: $2', '$0');
// parse the file in 1 go
while (($buffer = fgets($this->handle, $this->blocksize)) !== false) {
$result = preg_filter($pattern, $replace, $buffer);
if ($result) {
$info = explode(':', $result, 2);
}
}
if ($this->_flag_debug) {
echo "\nDependencies\n";
echo "---------------------\n";
print_r($this->depends);
echo "\nBuild Dependencies\n";
echo "---------------------\n";
print_r($this->buildDepends);
echo "\nProvides\n";
echo "---------------------\n";
print_r($this->provides);
echo "\nObsoletes\n";
echo "---------------------\n";
print_r($this->obsoletes);
echo "\nConflicts\n";
echo "---------------------\n";
print_r($this->conflicts);
echo "\nSubpackages\n";
echo "---------------------\n";
print_r($this->subpackages);
}
unset($buffer, $result, $info);
}
示例2: setLanguageFile
private function setLanguageFile()
{
//filter language file
$config = ParamesHelper::getLanguageConfig();
$this->adminArray = preg_filter('/^/', $this->language . '.', $config['file_admin']);
$this->siteArray = preg_filter('/^/', $this->language . '.', $config['file_site']);
$site_list_file = JFolder::files($config['folder_site'] . $this->language);
$this->itemsSite = MathHelper::filterArray($site_list_file, $this->siteArray);
$admin_list_file = JFolder::files($config['folder_admin'] . $this->language);
$this->itemsAdmin = MathHelper::filterArray($admin_list_file, $this->adminArray);
return true;
}
示例3: __construct
/**
* Construct the driver with the configuration.
*
* @param ConfigurationInterface $configuration The configuration to be used.
*
* @throws \InvalidArgumentException If wrong configuration class received.
*/
public function __construct(ConfigurationInterface $configuration)
{
// validate we get correct configuration class type.
$type = (string) preg_filter('/Zikula\\\\Component\\\\FileSystem\\\\(\\w+)$/', '$1', get_class($this));
$validName = "Zikula\\Component\\FileSystem\\Configuration\\{$type}Configuration";
if ($validName != get_class($configuration)) {
throw new \InvalidArgumentException(sprintf('Invalid configuration class for %1$s. Expected %2$s but got %3$s instead. ::%4$s', get_class($this), $validName, get_class($configuration), $type));
}
$this->configuration = $configuration;
$facade = "Zikula\\Component\\FileSystem\\Facade\\{$type}Facade";
$this->driver = new $facade();
$this->errorHandler = new Error();
}
示例4: run
/**
* Runs the test case.
* @return void
*/
public function run($method = NULL)
{
$r = new \ReflectionObject($this);
$methods = array_values(preg_grep(self::METHOD_PATTERN, array_map(function (\ReflectionMethod $rm) {
return $rm->getName();
}, $r->getMethods())));
if (substr($method, 0, 2) === '--') {
// back compatibility
$method = NULL;
}
if ($method === NULL && isset($_SERVER['argv']) && ($tmp = preg_filter('#(--method=)?([\\w-]+)$#Ai', '$2', $_SERVER['argv']))) {
$method = reset($tmp);
if ($method === self::LIST_METHODS) {
Environment::$checkAssertions = FALSE;
header('Content-Type: text/plain');
echo '[' . implode(',', $methods) . ']';
return;
}
}
if ($method === NULL) {
foreach ($methods as $method) {
$this->runMethod($method);
}
} elseif (in_array($method, $methods, TRUE)) {
$this->runMethod($method);
} else {
throw new TestCaseException("Method '{$method}' does not exist or it is not a testing method.");
}
}
示例5: iterateSubSelectors
private function iterateSubSelectors($container, $payload)
{
$nodes = $this->crawler->filter($container);
$results = array();
$collect = function ($node, $i) use($payload, &$results) {
$result = new \stdClass();
foreach ($payload as $label => $selector) {
if (is_string($selector)) {
$content = trim(strip_tags($node->filter($selector)->text()));
if ($label == "unit_price") {
$content = preg_filter(array("/£/", "/[a-z]/", "/\\//"), "", $content);
}
$result->{$label} = $content;
} elseif (is_array($selector)) {
switch ($selector['type']) {
case "link":
$link = $node->filter($selector['context'])->link();
$nextPageCrawler = self::$goutte->click($link);
if ($selector['target'] == 'content_size') {
$result->{$label} = intval(ceil(strlen(self::$goutte->getResponse()->getContent()) / 1024));
} else {
$content = $nextPageCrawler->filter($selector['target']);
$result->{$label} = trim(strip_tags($content->text()));
}
}
}
}
$results[] = $result;
};
$nodes->each($collect);
return $results;
}
示例6: matches
public function matches()
{
$url = $this->args;
foreach ($this->routes as $args) {
$path = preg_split('/\\//', $args['url']);
$path = preg_filter('/\\w+/', '$0', $path);
if (count($path) != count($url)) {
continue;
}
$callback = function (array $matches) use($url, $path, &$args) {
$key = array_search($matches[0], $path);
if ($key !== false && array_key_exists($key, $url)) {
$find = array_search($matches[1], $args);
if ($find !== false && array_key_exists($find, $args)) {
$args[$find] = $url[$key];
}
return $url[$key];
}
return $matches[1];
};
$path = preg_replace_callback('/\\((.\\w+)\\)/', $callback, $path);
$pattern = "^" . implode('\\/', $path);
if (preg_match("/{$pattern}/", $this->request)) {
if ($this->execute($args['controller'], $args['action'])) {
return $this;
}
}
}
throw new HTTP_Exception(404);
}
示例7: parse
protected static function parse($conf)
{
$routes = [];
$curpos = [];
foreach (explode("\n", $conf) as $line) {
if (($pos = strpos($line, '#')) !== false) {
$line = substr($line, 0, $pos);
}
if (!($line = rtrim($line))) {
continue;
}
$depth = strlen(preg_filter('/^(\\s+).*/', '$1', $line));
$data = preg_split('/\\s+/', ltrim($line));
$path = $data[0];
$node = $data[1] ?? null;
$curpos = array_slice($curpos, 0, $depth);
$curpos = array_pad($curpos, $depth, '');
$curpos[] = $path;
if (!$node) {
continue;
}
$line = preg_replace('/^\\s*.*?\\s+/', '', $line);
$path = preg_replace('/\\/+/', '/', '/' . join('/', $curpos));
$node = preg_replace('/\\s*/', '', $line);
$patt = str_replace('.', '\\.', $path);
$patt = preg_replace('/:\\w+/', '([^/]+)', $patt);
$patt = preg_replace('/@\\w+/', '(\\d+)', $patt);
$class = preg_replace('/\\//', '\\controller\\', dirname($node), 1);
$class = preg_replace('/\\//', '\\', $class);
$routes[] = ['path' => $path, 'controller' => dirname($node), 'action' => basename($node), 'pattern' => $patt, 'class' => $class];
}
return $routes;
}
示例8: addParam
public static function addParam($parameter, $params)
{
$params = preg_filter("/[\\{]?([^\\}]*)[\\}]?/si", "\$1", $params, 1);
$values = explode(",", $params);
$values[] = $parameter;
return "{" . implode(",", $values) . "}";
}
示例9: is_hello
private function is_hello($str)
{
$a = $str . "q";
$a = preg_filter("([^hello])", "", $a);
$r = preg_filter(["(he)", "(2ll)", "([^3o])", "(3o)", "(o)"], ["2", "3", "", "4", ""], $a);
return $r == "4" ? true : false;
}
示例10: blowfishHash
public function blowfishHash($data, $cost = null, $alpha = null, $prefix = null)
{
if ($alpha !== null) {
$alpha = preg_filter('/[^.\\/0-9a-z]/i', '', $alpha);
if (strlen($alpha) > 22) {
$alpha = substr($alpha, 0, 22);
}
}
if ($prefix !== null) {
switch ($prefix) {
case '$2x$':
case '$2y$':
break;
case '$2a$':
$prefix = '$2x$';
break;
case '$2$':
default:
$prefix = null;
break;
}
}
$salt = $this->blowfishSalt($cost, $alpha, $prefix);
return crypt($data . $alpha, $salt['salt']);
}
示例11: listing
/**
* Return array of diff files only
*
* Scans the specified directory, discards all found items
* except files with the extension ".diff" and returns array with it.
*
* @param string $dir
* @return array
*/
public function listing($dir)
{
$dir = empty($dir) || !is_dir($dir) ? realpath(__DIR__ . '/../') : $dir;
$list = scandir($dir);
$list = preg_filter('/.\\.diff$/i', '$0', $list);
return $list;
}
示例12: format
/**
* format()
* Formata a mensagem recebida
*
* @version
* 1.0 Initial
*
* @param string $message Mensagem a ser formatada
* @return string Mensagem formatada
*/
public function format($message)
{
foreach ($this->patterns as $pattern => $replace) {
preg_match($pattern, $message, $out);
}
return preg_filter(array_keys($this->patterns), array_values($this->patterns), $message);
}
示例13: testSimpleLambda
public function testSimpleLambda()
{
$lambdaFunc = function ($word) {
return preg_filter("/my/i", "", $word);
};
$stemmer = new LambdaStemmer($lambdaFunc);
$this->assertEquals("tom", $stemmer->stem("tommy"));
}
示例14: __call
public function __call($name, $parameters)
{
if (preg_match('/Complete$/', $name)) {
$name = preg_filter('/Complete$/', '', $name);
return $this->_Complete($name, $parameters);
}
return $this->_callFunction($name, $parameters);
}
示例15: _preg_filter
/**
* Perform a regular expression search and replace, returning only matched subjects.
*
* @param string $subject
* @param string $pattern
* @param string $replacement
* @param int $limit
*
* @return string
*/
public function _preg_filter($subject, $pattern, $replacement = '', $limit = -1)
{
if (!isset($subject)) {
return;
} else {
return preg_filter($pattern, $replacement, $subject, $limit);
}
}