PKPString::regexp_match_all PHP Method

regexp_match_all() static public method

See also: http://ca.php.net/manual/en/function.regexp_match_all.php
static public regexp_match_all ( $pattern, $subject, &$matches ) : integer | boolean
$pattern string Regular expression
$subject string String to apply regular expression to
$matches array Reference to receive matches
return integer | boolean Returns number of full matches of given subject, or FALSE if an error occurred.
    static function regexp_match_all($pattern, $subject, &$matches)
    {
        if (PCRE_UTF8 && !self::utf8_compliant($subject)) {
            $subject = self::utf8_bad_strip($subject);
        }
        return preg_match_all($pattern . PCRE_UTF8, $subject, $matches);
    }

Usage Example

 /**
  * 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;
 }
All Usage Examples Of PKPString::regexp_match_all