当前位置: 首页>>代码示例>>PHP>>正文


PHP PKPString::regexp_match_all方法代码示例

本文整理汇总了PHP中PKPString::regexp_match_all方法的典型用法代码示例。如果您正苦于以下问题:PHP PKPString::regexp_match_all方法的具体用法?PHP PKPString::regexp_match_all怎么用?PHP PKPString::regexp_match_all使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在PKPString的用法示例。


在下文中一共展示了PKPString::regexp_match_all方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: trim

 /**
  * Converts a string with multiple persons
  * to an array of NLM name descriptions.
  *
  * @param $personsString string
  * @param $title boolean true to parse for title
  * @param $degrees boolean true to parse for degrees
  * @return array an array of NLM name descriptions or null
  *  if the string could not be converted plus optionally a
  *  single 'et-al' string.
  */
 function &_parsePersonsString($personsString, $title, $degrees)
 {
     // Check for 'et al'.
     $personsStringBeforeEtal = PKPString::strlen($personsString);
     $personsString = PKPString::regexp_replace('/et ?al$/', '', $personsString);
     $etAl = $personsStringBeforeEtal == PKPString::strlen($personsString) ? false : true;
     // Remove punctuation.
     $personsString = trim($personsString, ':;, ');
     // Cut the authors string into pieces.
     $personStrings = PKPString::iterativeExplode(array(':', ';'), $personsString);
     // If we did not have success with simple patterns then try more complex
     // patterns to tokenize multiple-person strings.
     if (count($personStrings) == 1) {
         // The first pattern must match the whole string, the second is used
         // to extract names.
         $complexPersonsPatterns = array(array('/^((([^ \\t\\n\\r\\f\\v,.&]{2,}\\s*)+,\\s*([A-Z]\\.\\s*)+),\\s*)+(\\&|\\.\\s\\.\\s\\.)\\s*([^ \\t\\n\\r\\f\\v,.&]{2,}\\s*,\\s*([A-Z]\\.\\s*)+)$/i', '/(?:[^ \\t\\n\\r\\f\\v,.&]{2,}\\s*)+,\\s*(?:[A-Z]\\.\\s*)+/i'), array('/^((([^ \\t\\n\\r\\f\\v,&]+\\s+)+[^ \\t\\n\\r\\f\\v,&]+\\s*)[,&]\\s*)+(([^ \\t\\n\\r\\f\\v,&]+\\s+)+[^ \\t\\n\\r\\f\\v,&]+)/i', '/(?:(?:[^ \\t\\n\\r\\f\\v,&.]+|[^ \\t\\n\\r\\f\\v,&]{2,})\\s+)+(?:[^ \\t\\n\\r\\f\\v,&.]+|[^ \\t\\n\\r\\f\\v,&]{2,})/i'));
         $matched = false;
         foreach ($complexPersonsPatterns as $complexPersonsPattern) {
             // Break at the first pattern that matches.
             if ($matched = PKPString::regexp_match($complexPersonsPattern[0], $personsString)) {
                 // Retrieve names.
                 $success = PKPString::regexp_match_all($complexPersonsPattern[1], $personsString, $personStrings);
                 assert($success && count($personStrings) == 1);
                 $personStrings = $personStrings[0];
                 break;
             }
         }
         if (!$matched) {
             // If nothing matches then try to parse as a single person.
             $personStrings = array($personsString);
         }
     }
     // Parse persons.
     $persons = array();
     foreach ($personStrings as $personString) {
         $persons[] =& $this->_parsePersonString($personString, $title, $degrees);
     }
     // Add et-al string.
     if ($etAl) {
         $persons[] = PERSON_STRING_FILTER_ETAL;
     }
     return $persons;
 }
开发者ID:PublishingWithoutWalls,项目名称:pkp-lib,代码行数:54,代码来源:PersonStringNlm30NameSchemaFilter.inc.php

示例2: array

 /**
  * @see Filter::process()
  * @param $citationDescription MetadataDescription
  * @return string a DOI or null
  */
 function &process(&$citationDescription)
 {
     $nullVar = null;
     // Get the search strings
     $searchTemplates =& $this->_getSearchTemplates();
     $searchStrings = $this->constructSearchStrings($searchTemplates, $citationDescription);
     // Run the searches, in order, until we have a result
     $searchParams = array('qt' => 'worldcat_org_all');
     foreach ($searchStrings as $searchString) {
         $searchParams['q'] = $searchString;
         // Worldcat Web search; results are (mal-formed) XHTML
         if (is_null($result = $this->callWebService(WORLDCAT_WEBSERVICE_SEARCH, $searchParams, XSL_TRANSFORMER_DOCTYPE_STRING))) {
             return $nullVar;
         }
         // parse the OCLC numbers from search results
         PKPString::regexp_match_all('/id="itemid_(\\d+)"/', $result, $matches);
         if (!empty($matches[1])) {
             break;
         }
     }
     // If we don't have an OCLC number, then we cannot get any metadata
     if (empty($matches[1])) {
         return $nullVar;
     }
     // use xISBN because it's free
     foreach ($matches[1] as $oclcId) {
         $isbns = $this->_oclcToIsbns($oclcId);
         if (is_array($isbns)) {
             break;
         }
     }
     if (is_null($isbns)) {
         return $nullVar;
     }
     $apiKey = $this->getApiKey();
     if (empty($apiKey)) {
         // Use the first ISBN if we have multiple
         $citationDescription =& $this->_lookupXIsbn($isbns[0]);
         return $citationDescription;
     } elseif (!empty($isbns[0])) {
         // Worldcat lookup only works with an API key
         if (is_null($citationDescription =& $this->_lookupWorldcat($matches[1][0]))) {
             return $nullVar;
         }
         // Prefer ISBN from xISBN if possible
         if (!empty($isbns[0])) {
             $citationDescription->addStatement('ibsn', $isbns[0], null, true);
         }
         return $citationDescription;
     }
     // Nothing found
     return $nullVar;
 }
开发者ID:PublishingWithoutWalls,项目名称:pkp-lib,代码行数:58,代码来源:WorldcatNlm30CitationSchemaFilter.inc.php

示例3: getParameterNames

 /**
  * Given a locale string, get the list of parameter references of the
  * form {$myParameterName}.
  * @param $source string
  * @return array
  */
 static function getParameterNames($source)
 {
     $matches = null;
     PKPString::regexp_match_all('/({\\$[^}]+})/', $source, $matches);
     array_shift($matches);
     // Knock the top element off the array
     if (isset($matches[0])) {
         return $matches[0];
     }
     return array();
 }
开发者ID:jalperin,项目名称:pkp-lib,代码行数:17,代码来源:PKPLocale.inc.php

示例4: array

 /**
  * Parse SQL content into individual SQL statements.
  * @param $sql string
  * @return array
  */
 function &parseStatements(&$sql)
 {
     $statements = array();
     $statementsTmp = explode($this->statementDelim, $sql);
     $currentStatement = '';
     $numSingleQuotes = $numEscapedSingleQuotes = 0;
     // This method for parsing the SQL statements was adapted from one used in phpBB (http://www.phpbb.com/)
     for ($i = 0, $count = count($statementsTmp); $i < $count; $i++) {
         // Get total number of single quotes in string
         $numSingleQuotes += PKPString::substr_count($statementsTmp[$i], "'");
         // Get number of escaped single quotes
         $numEscapedSingleQuotes += PKPString::regexp_match_all("/(?<!\\\\)(\\\\\\\\)*\\\\'/", $statementsTmp[$i], $matches);
         $currentStatement .= $statementsTmp[$i];
         if (($numSingleQuotes - $numEscapedSingleQuotes) % 2 == 0) {
             // Even number of unescaped single quotes, so statement must be complete
             if (trim($currentStatement) !== '') {
                 array_push($statements, trim($currentStatement));
             }
             $currentStatement = '';
             $numSingleQuotes = $numEscapedSingleQuotes = 0;
         } else {
             // The statement is not complete, the delimiter must be inside the statement
             $currentStatement .= $this->statementDelim;
         }
     }
     return $statements;
 }
开发者ID:jprk,项目名称:pkp-lib,代码行数:32,代码来源:SQLParser.inc.php


注:本文中的PKPString::regexp_match_all方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。