本文整理匯總了PHP中preg_match_all函數的典型用法代碼示例。如果您正苦於以下問題:PHP preg_match_all函數的具體用法?PHP preg_match_all怎麽用?PHP preg_match_all使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了preg_match_all函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: addComplexType
/**
* Add a complex type by recursivly using all the class properties fetched via Reflection.
*
* @param string $type Name of the class to be specified
* @return string XSD Type for the given PHP type
*/
public function addComplexType($type)
{
if (!class_exists($type)) {
throw new \Zend\Soap\WSDL\Exception(sprintf('Cannot add a complex type %s that is not an object or where ' . 'class could not be found in \'DefaultComplexType\' strategy.', $type));
}
$dom = $this->getContext()->toDomDocument();
$class = new \ReflectionClass($type);
$complexType = $dom->createElement('xsd:complexType');
$complexType->setAttribute('name', $type);
$all = $dom->createElement('xsd:all');
foreach ($class->getProperties() as $property) {
if ($property->isPublic() && preg_match_all('/@var\\s+([^\\s]+)/m', $property->getDocComment(), $matches)) {
/**
* @todo check if 'xsd:element' must be used here (it may not be compatible with using 'complexType'
* node for describing other classes used as attribute types for current class
*/
$element = $dom->createElement('xsd:element');
$element->setAttribute('name', $property->getName());
$element->setAttribute('type', $this->getContext()->getType(trim($matches[1][0])));
$all->appendChild($element);
}
}
$complexType->appendChild($all);
$this->getContext()->getSchema()->appendChild($complexType);
$this->getContext()->addType($type);
return "tns:{$type}";
}
示例2: convertDateMomentToPhp
public static function convertDateMomentToPhp($format)
{
$tokens = ["M" => "n", "Mo" => "nS", "MM" => "m", "MMM" => "M", "MMMM" => "F", "D" => "j", "Do" => "jS", "DD" => "d", "DDD" => "z", "DDDo" => "zS", "DDDD" => "zS", "d" => "w", "do" => "wS", "dd" => "D", "ddd" => "D", "dddd" => "l", "e" => "w", "E" => "N", "w" => "W", "wo" => "WS", "ww" => "W", "W" => "W", "Wo" => "WS", "WW" => "W", "YY" => "y", "YYYY" => "Y", "gg" => "o", "gggg" => "o", "GG" => "o", "GGGG" => "o", "A" => "A", "a" => "a", "H" => "G", "HH" => "H", "h" => "g", "hh" => "h", "m" => "i", "mm" => "i", "s" => "s", "ss" => "s", "S" => "", "SS" => "", "SSS" => "", "z or zz" => "T", "Z" => "P", "ZZ" => "O", "X" => "U", "LT" => "g:i A", "L" => "m/d/Y", "l" => "n/j/Y", "LL" => "F jS Y", "ll" => "M j Y", "LLL" => "F js Y g:i A", "lll" => "M j Y g:i A", "LLLL" => "l, F jS Y g:i A", "llll" => "D, M j Y g:i A"];
// find all tokens from string, using regular expression
$regExp = "/(\\[[^\\[]*\\])|(\\\\)?(LT|LL?L?L?|l{1,4}|Mo|MM?M?M?|Do|DDDo|DD?D?D?|ddd?d?|do?|w[o|w]?|W[o|W]?|YYYYY|YYYY|YY|gg(ggg?)?|GG(GGG?)?|e|E|a|A|hh?|HH?|mm?|ss?|SS?S?|X|zz?|ZZ?|.)/";
$matches = array();
preg_match_all($regExp, $format, $matches);
// if there is no match found then return the string as it is
// TODO: might return escaped string
if (empty($matches) || is_array($matches) === false) {
return $format;
}
// to match with extracted tokens
$momentTokens = array_keys($tokens);
$phpMatches = array();
// ----------------------------------
foreach ($matches[0] as $id => $match) {
// if there is a matching php token in token list
if (in_array($match, $momentTokens)) {
// use the php token instead
$string = $tokens[$match];
} else {
$string = $match;
}
$phpMatches[$id] = $string;
}
// join and return php specific tokens
return implode("", $phpMatches);
}
示例3: imitateLogin
public function imitateLogin($sdutnum, $password)
{
//模擬登錄
$cookie_jar = dirname(__FILE__) . "/cookie";
$urlLogin = "http://222.206.65.12/reader/redr_verify.php";
$post = "number={$sdutnum}&passwd={$password}&select=cert_no&returnUrl=";
$this->curl->login_post($urlLogin, $cookie_jar, $post);
//抓取內容
$urlBook = "http://222.206.65.12/reader/book_lst.php";
$html = $this->curl->get_content($urlBook, $cookie_jar);
$loginReg = "/logout/";
$BookReg = "/<td.*/";
$buttonReg = "/<div\\sid=\"\\w\"><input.*\\/>/";
$nameReg = '/height="11" \\/>.*logout/';
$numReg = '/<p>.*<b/';
//book number
preg_match_all($loginReg, $html, $isLogin);
//to judgment whether login
preg_match_all($BookReg, $html, $bookArray);
preg_match_all($buttonReg, $html, $buttonArray);
preg_match_all($nameReg, $html, $nameArray);
//username
preg_match_all($numReg, $html, $numArray);
empty($nameArray[0]) ? $username = null : ($username = substr($nameArray[0][0], 14, -37));
empty($numArray[0]) ? $bookNum = null : ($bookNum = substr($numArray[0][0], 45, -25));
$bookData['sdutnum'] = $sdutnum;
/* after changed session*/
$bookData['isLogin'] = $isLogin;
$bookData['bookArray'] = $bookArray;
$bookData['buttonArray'] = $buttonArray;
$bookData['username'] = $username;
$bookData['numArray'] = $numArray;
$bookData['bookNum'] = $bookNum;
return $bookData;
}
示例4: PMA_sanitize
/**
* Sanitizes $message, taking into account our special codes
* for formatting.
*
* If you want to include result in element attribute, you should escape it.
*
* Examples:
*
* <p><?php echo PMA_sanitize($foo); ?></p>
*
* <a title="<?php echo PMA_sanitize($foo, true); ?>">bar</a>
*
* @uses preg_replace()
* @uses strtr()
* @param string the message
* @param boolean whether to escape html in result
*
* @return string the sanitized message
*
* @access public
*/
function PMA_sanitize($message, $escape = false, $safe = false)
{
if (!$safe) {
$message = strtr($message, array('<' => '<', '>' => '>'));
}
$replace_pairs = array('[i]' => '<em>', '[/i]' => '</em>', '[em]' => '<em>', '[/em]' => '</em>', '[b]' => '<strong>', '[/b]' => '</strong>', '[strong]' => '<strong>', '[/strong]' => '</strong>', '[tt]' => '<code>', '[/tt]' => '</code>', '[code]' => '<code>', '[/code]' => '</code>', '[kbd]' => '<kbd>', '[/kbd]' => '</kbd>', '[br]' => '<br />', '[/a]' => '</a>', '[sup]' => '<sup>', '[/sup]' => '</sup>');
$message = strtr($message, $replace_pairs);
$pattern = '/\\[a@([^"@]*)@([^]"]*)\\]/';
if (preg_match_all($pattern, $message, $founds, PREG_SET_ORDER)) {
$valid_links = array('http', './Do', './ur');
foreach ($founds as $found) {
// only http... and ./Do... allowed
if (!in_array(substr($found[1], 0, 4), $valid_links)) {
return $message;
}
// a-z and _ allowed in target
if (!empty($found[2]) && preg_match('/[^a-z_]+/i', $found[2])) {
return $message;
}
}
if (substr($found[1], 0, 4) == 'http') {
$message = preg_replace($pattern, '<a href="' . PMA_linkURL($found[1]) . '" target="\\2">', $message);
} else {
$message = preg_replace($pattern, '<a href="\\1" target="\\2">', $message);
}
}
if ($escape) {
$message = htmlspecialchars($message);
}
return $message;
}
示例5: loadColumnData
protected function loadColumnData($table, $schema)
{
if (isset($this->data['columns'][$schema][$table])) {
return;
}
$this->prepareDataHierarchy('columns', $schema, $table);
$p = $this->adapter->getPlatform();
$isColumns = array(array('C', 'ORDINAL_POSITION'), array('C', 'COLUMN_DEFAULT'), array('C', 'IS_NULLABLE'), array('C', 'DATA_TYPE'), array('C', 'CHARACTER_MAXIMUM_LENGTH'), array('C', 'CHARACTER_OCTET_LENGTH'), array('C', 'NUMERIC_PRECISION'), array('C', 'NUMERIC_SCALE'), array('C', 'COLUMN_NAME'), array('C', 'COLUMN_TYPE'));
array_walk($isColumns, function (&$c) use($p) {
$c = $p->quoteIdentifierChain($c);
});
$sql = 'SELECT ' . implode(', ', $isColumns) . ' FROM ' . $p->quoteIdentifierChain(array('INFORMATION_SCHEMA', 'TABLES')) . 'T' . ' INNER JOIN ' . $p->quoteIdentifierChain(array('INFORMATION_SCHEMA', 'COLUMNS')) . 'C' . ' ON ' . $p->quoteIdentifierChain(array('T', 'TABLE_SCHEMA')) . ' = ' . $p->quoteIdentifierChain(array('C', 'TABLE_SCHEMA')) . ' AND ' . $p->quoteIdentifierChain(array('T', 'TABLE_NAME')) . ' = ' . $p->quoteIdentifierChain(array('C', 'TABLE_NAME')) . ' WHERE ' . $p->quoteIdentifierChain(array('T', 'TABLE_TYPE')) . ' IN (\'BASE TABLE\', \'VIEW\')' . ' AND ' . $p->quoteIdentifierChain(array('T', 'TABLE_NAME')) . ' = ' . $p->quoteTrustedValue($table);
if ($schema != self::DEFAULT_SCHEMA) {
$sql .= ' AND ' . $p->quoteIdentifierChain(array('T', 'TABLE_SCHEMA')) . ' = ' . $p->quoteTrustedValue($schema);
} else {
$sql .= ' AND ' . $p->quoteIdentifierChain(array('T', 'TABLE_SCHEMA')) . ' != \'INFORMATION_SCHEMA\'';
}
$results = $this->adapter->query($sql, Adapter::QUERY_MODE_EXECUTE);
$columns = array();
foreach ($results->toArray() as $row) {
$erratas = array();
$matches = array();
if (preg_match('/^(?:enum|set)\\((.+)\\)$/i', $row['COLUMN_TYPE'], $matches)) {
$permittedValues = $matches[1];
if (preg_match_all("/\\s*'((?:[^']++|'')*+)'\\s*(?:,|\$)/", $permittedValues, $matches, PREG_PATTERN_ORDER)) {
$permittedValues = str_replace("''", "'", $matches[1]);
} else {
$permittedValues = array($permittedValues);
}
$erratas['permitted_values'] = $permittedValues;
}
$columns[$row['COLUMN_NAME']] = array('ordinal_position' => $row['ORDINAL_POSITION'], 'column_default' => $row['COLUMN_DEFAULT'], 'is_nullable' => 'YES' == $row['IS_NULLABLE'], 'data_type' => $row['DATA_TYPE'], 'character_maximum_length' => $row['CHARACTER_MAXIMUM_LENGTH'], 'character_octet_length' => $row['CHARACTER_OCTET_LENGTH'], 'numeric_precision' => $row['NUMERIC_PRECISION'], 'numeric_scale' => $row['NUMERIC_SCALE'], 'numeric_unsigned' => false !== strpos($row['COLUMN_TYPE'], 'unsigned'), 'erratas' => $erratas);
}
$this->data['columns'][$schema][$table] = $columns;
}
示例6: get_dependencies
private function get_dependencies()
{
preg_match_all('/#dependency (.*)/', $this->output, $dependencies);
foreach ($dependencies[1] as $dependency) {
$this->dependencies[] = trim($dependency);
}
}
示例7: filtre_picture
/**
* On modifie les URLS des images dans le corps de l'article
*/
function filtre_picture($content, $url, $id)
{
$matches = array();
$processing_pictures = array();
// list of processing image to avoid processing the same pictures twice
preg_match_all('#<\\s*(img)[^>]+src="([^"]*)"[^>]*>#Si', $content, $matches, PREG_SET_ORDER);
foreach ($matches as $i => $link) {
$link[1] = trim($link[1]);
if (!preg_match('#^(([a-z]+://)|(\\#))#', $link[1])) {
$absolute_path = get_absolute_link($link[2], $url);
$filename = basename(parse_url($absolute_path, PHP_URL_PATH));
$directory = create_assets_directory($id);
$fullpath = $directory . '/' . $filename;
if (in_array($absolute_path, $processing_pictures) === true) {
// replace picture's URL only if processing is OK : already processing -> go to next picture
continue;
}
if (download_pictures($absolute_path, $fullpath) === true) {
$content = str_replace($matches[$i][2], $fullpath, $content);
}
$processing_pictures[] = $absolute_path;
}
}
return $content;
}
示例8: index
function index()
{
$path = \GCore\C::get('GCORE_ADMIN_PATH') . 'extensions' . DS . 'chronoforms' . DS;
$files = \GCore\Libs\Folder::getFiles($path, true);
$strings = array();
//function to prepare strings
$prepare = function ($str) {
/*$path = \GCore\C::get('GCORE_FRONT_PATH');
if(strpos($str, $path) !== false AND strpos($str, $path) == 0){
return '//'.str_replace($path, '', $str);
}*/
$val = !empty(\GCore\Libs\Lang::$translations[$str]) ? \GCore\Libs\Lang::$translations[$str] : '';
return 'const ' . trim($str) . ' = "' . str_replace("\n", '\\n', $val) . '";';
};
foreach ($files as $file) {
if (substr($file, -4, 4) == '.php') {
// AND strpos($file, DS.'extensions'.DS) === TRUE){
//$strings[] = $file;
$file_code = file_get_contents($file);
preg_match_all('/l_\\(("|\')([^(\\))]*?)("|\')\\)/i', $file_code, $langs);
if (!empty($langs[2])) {
$strings = array_merge($strings, $langs[2]);
}
}
}
$strings = array_unique($strings);
$strings = array_map($prepare, $strings);
echo '<textarea rows="20" cols="80">' . implode("\n", $strings) . '</textarea>';
}
示例9: Download
public function Download($link)
{
global $premium_acc;
// check link
if (preg_match('@http:\\/\\/filejungle\\.com\\/l\\/[^|\\r|\\n]+@i', $link, $dir)) {
if (!$dir[0]) {
html_error('Filejungle folder link can\'t be found!');
}
$check = $this->GetPage($link);
preg_match_all('@http:\\/\\/www\\.filejungle\\.com\\/f\\/[^"]+@i', $check, $fj, PREG_SET_ORDER);
$arr_link = array();
foreach ($fj as $match) {
$arr_link[] = $match[0];
}
if (!$arr_link) {
html_error('Can\'t find filejungle single link, probably folder is empty?');
}
$this->moveToAutoDownloader($arr_link);
}
if ($_REQUEST['premium_acc'] == 'on' && $_REQUEST['premium_user'] && $_REQUEST['premium_pass'] || $_REQUEST['premium_acc'] == 'on' && $premium_acc['filejungle_com']['user'] && $premium_acc['filejungle_com']['pass']) {
return $this->Premium($link);
} else {
return $this->Free($link);
}
}
示例10: getMaxColumns
/**
* Counting terminal char width
* @return int
*/
private static function getMaxColumns()
{
if (preg_match_all("/columns.([0-9]+);/", strtolower(@exec('stty -a | grep columns')), $output) && 2 == sizeof($output)) {
return $output[1][0];
}
return 80;
}
示例11: createRow
protected function createRow($items, $aData = array(), $level = 1)
{
if ($items->count()) {
foreach ($items as $itm) {
$getter = 'get' . $this->getValueField();
$aResultTmp = array('Value' => call_user_func(array($itm, $getter)), 'Name' => $this->getTextFormat());
$aRs = array();
if (preg_match_all("/:(.*):/iU", $aResultTmp['Name'], $aRs)) {
foreach ($aRs[1] as $k => $val) {
$value = $itm;
if (strpos($val, "-") !== false) {
$xVal = explode("-", $val);
foreach ($xVal as $_val) {
$sGetter = 'get' . $_val;
$value = call_user_func(array($value, $sGetter));
}
} else {
$sGetter = 'get' . $val;
$value = call_user_func(array($value, $sGetter));
}
$aResultTmp['Name'] = str_replace($aRs[0][$k], $value, $aResultTmp['Name']);
}
}
if ($this->getIsTree() && $level > 1) {
$aResultTmp['Name'] = str_repeat(" |-- ", $level - 1) . $aResultTmp['Name'];
}
$aData[] = $aResultTmp;
if ($itm->hasChilds()) {
$aData = $this->createRow($itm->getChilds(), $aData, $level + 1);
}
}
}
return $aData;
}
示例12: extractPage
public function extractPage($pageID, $pageTitle, $pageSource)
{
$result = new ExtractionResult($pageID, $this->language, $this->getExtractorID());
$category = Util::getMediaWikiNamespace($this->language, MW_CATEGORY_NAMESPACE);
if (preg_match_all("/" . $category . ":(.*)/", $pageID, $match)) {
$result->addTriple($this->getPageURI(), RDFtriple::URI(SKOS_PREFLABEL, false), RDFtriple::Literal($this->decode_title($pageTitle), NULL, $this->language));
$result->addTriple($this->getPageURI(), RDFtriple::URI(RDF_TYPE, false), RDFtriple::URI(SKOS_CONCEPT, false));
if (preg_match_all("/\\[\\[" . $category . ":(.*)\\]\\]/", $pageSource, $matches, PREG_SET_ORDER)) {
foreach ($matches as $match) {
// split on | sign
if (strpos($match[1], '|') === false) {
$object = Util::getDBpediaCategoryPrefix($this->language) . URI::wikipediaEncode($match[1]);
} else {
$split = explode('|', $match[1]);
$object = Util::getDBpediaCategoryPrefix($this->language) . URI::wikipediaEncode($split[0]);
}
try {
$object = RDFtriple::URI($object);
} catch (Exception $e) {
echo 'Caught exception: ', $e->getMessage(), "\n";
continue;
}
$result->addTriple($this->getPageURI(), RDFtriple::URI(SKOS_BROADER, false), $object);
}
}
}
return $result;
}
示例13: parseParameters
private static function parseParameters($text)
{
$text = preg_replace('/[\\x{00a0}\\x{200b}]+/u', ' ', $text);
if (!preg_match_all(static::$argumentsRegex, $text, $matches, PREG_SET_ORDER)) {
return ltrim($text) ? array(ltrim($text) => null) : array();
}
$parameters = array();
foreach ($matches as $match) {
if (!empty($match[1])) {
$parameters[strtolower($match[1])] = stripcslashes($match[2]);
} elseif (!empty($match[3])) {
$parameters[strtolower($match[3])] = stripcslashes($match[4]);
} elseif (!empty($match[5])) {
$parameters[strtolower($match[5])] = stripcslashes($match[6]);
} elseif (isset($match[7]) && strlen($match[7])) {
$parameters[stripcslashes($match[7])] = null;
} elseif (isset($match[8])) {
$parameters[stripcslashes($match[8])] = null;
}
}
foreach ($parameters as $key => $value) {
if (false !== strpos($value, '<') && 1 !== preg_match('/^[^<]*+(?:<[^>]*+>[^<]*+)*+$/', $value)) {
$parameters[$key] = '';
}
}
return $parameters;
}
示例14: get_recipe
function get_recipe($recipe)
{
global $doc, $xpath;
$url = 'http://www.marmiton.org/recettes/recherche.aspx?aqt=' . urlencode($recipe);
$pageList = file_get_contents($url);
// get response list and match recipes titles
if (preg_match_all('#m_titre_resultat[^\\<]*<a .*title="(.+)".* href="(.+)"#isU', $pageList, $matchesList)) {
// echo"<xmp>";print_r($matchesList[1]);echo"</xmp>";
// for each recipes titles
// foreach($matchesList[1] as $recipeTitle) {
// }
// take first recipe
$n = 0;
$url = 'http://www.marmiton.org' . $matchesList[2][$n];
$pageRecipe = file_get_contents($url);
// get recipe (minimize/clean before dom load)
if (preg_match('#<div class="m_content_recette_main">.*<div id="recipePrevNext2"></div>\\s*</div>#isU', $pageRecipe, $match)) {
$recipe = $match[0];
$recipe = preg_replace('#<script .*</script>#isU', '', $recipe);
$doc = loadDOC($pageRecipe);
$xpath = new DOMXpath($doc);
$recipeTitle = fetchOne('//h1[@class="m_title"]');
$recipeMain = fetchOne('//div[@class="m_content_recette_main"]');
return '<div class="recipe_root">' . $recipeTitle . $recipeMain . '</div>';
}
}
}
示例15: smarty_outputfilter_trimwhitespace
/**
* Smarty trimwhitespace outputfilter plugin
*
* File: outputfilter.trimwhitespace.php<br>
* Type: outputfilter<br>
* Name: trimwhitespace<br>
* Date: Jan 25, 2003<br>
* Purpose: trim leading white space and blank lines from
* template source after it gets interpreted, cleaning
* up code and saving bandwidth. Does not affect
* <<PRE>></PRE> and <SCRIPT></SCRIPT> blocks.<br>
* Install: Drop into the plugin directory, call
* <code>$smarty->load_filter('output','trimwhitespace');</code>
* from application.
* @author Monte Ohrt <monte at ohrt dot com>
* @author Contributions from Lars Noschinski <lars@usenet.noschinski.de>
* @version 1.3
* @param string $source input string
* @param object &$smarty Smarty object
* @return string filtered output
*/
function smarty_outputfilter_trimwhitespace($source, $smarty)
{
// Pull out the script blocks
preg_match_all("!<script[^>]*?>.*?</script>!is", $source, $match);
$_script_blocks = $match[0];
$source = preg_replace("!<script[^>]*?>.*?</script>!is", '@@@SMARTY:TRIM:SCRIPT@@@', $source);
// Pull out the pre blocks
preg_match_all("!<pre[^>]*?>.*?</pre>!is", $source, $match);
$_pre_blocks = $match[0];
$source = preg_replace("!<pre[^>]*?>.*?</pre>!is", '@@@SMARTY:TRIM:PRE@@@', $source);
// Pull out the textarea blocks
preg_match_all("!<textarea[^>]*?>.*?</textarea>!is", $source, $match);
$_textarea_blocks = $match[0];
$source = preg_replace("!<textarea[^>]*?>.*?</textarea>!is", '@@@SMARTY:TRIM:TEXTAREA@@@', $source);
// remove all leading spaces, tabs and carriage returns NOT
// preceeded by a php close tag.
$source = trim(preg_replace('/((?<!\\?>)\\n)[\\s]+/m', '\\1', $source));
// replace textarea blocks
smarty_outputfilter_trimwhitespace_replace("@@@SMARTY:TRIM:TEXTAREA@@@", $_textarea_blocks, $source);
// replace pre blocks
smarty_outputfilter_trimwhitespace_replace("@@@SMARTY:TRIM:PRE@@@", $_pre_blocks, $source);
// replace script blocks
smarty_outputfilter_trimwhitespace_replace("@@@SMARTY:TRIM:SCRIPT@@@", $_script_blocks, $source);
return $source;
}