PKPString::regexp_match_get PHP Method

regexp_match_get() static public method

See also: http://ca.php.net/manual/en/function.regexp_match_get.php
static public regexp_match_get ( $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 1 if the pattern matches given subject, 0 if it does not, or FALSE if an error occurred.
    static function regexp_match_get($pattern, $subject, &$matches)
    {
        // NOTE: This function was created since PHP < 5.x does not support optional reference parameters
        if (PCRE_UTF8 && !self::utf8_compliant($subject)) {
            $subject = self::utf8_bad_strip($subject);
        }
        return preg_match($pattern . PCRE_UTF8, $subject, $matches);
    }

Usage Example

 /**
  * Retrieve the export as an XML string.
  * @param $pluginUrl string the url to be requested for export.
  * @param $postParams array additional post parameters
  * @return string
  */
 protected function getXmlOnExport($pluginUrl, $postParams = array())
 {
     // Prepare HTTP session.
     $curlCh = curl_init();
     curl_setopt($curlCh, CURLOPT_POST, true);
     // Create a cookie file (required for log-in).
     $cookies = tempnam(sys_get_temp_dir(), 'curlcookies');
     // Log in.
     $loginUrl = $this->baseUrl . '/index.php/test/login/signIn';
     // Bug #8518 safety work-around
     if ($this->password[0] == '@') {
         die('CURL parameters may not begin with @.');
     }
     $loginParams = array('username' => 'admin', 'password' => $this->password);
     curl_setopt($curlCh, CURLOPT_URL, $loginUrl);
     curl_setopt($curlCh, CURLOPT_POSTFIELDS, $loginParams);
     curl_setopt($curlCh, CURLOPT_COOKIEJAR, $cookies);
     self::assertTrue(curl_exec($curlCh));
     // Request export document.
     $exportUrl = $this->baseUrl . '/index.php/test/manager/importexport/plugin/' . $pluginUrl;
     curl_setopt($curlCh, CURLOPT_URL, $exportUrl);
     // Bug #8518 safety work-around
     foreach ($postParams as $paramValue) {
         if ($paramValue[0] == '@') {
             die('CURL parameters may not begin with @.');
         }
     }
     curl_setopt($curlCh, CURLOPT_POSTFIELDS, $postParams);
     curl_setopt($curlCh, CURLOPT_HTTPHEADER, array('Accept: application/xml, application/x-gtar, */*'));
     curl_setopt($curlCh, CURLOPT_RETURNTRANSFER, true);
     curl_setopt($curlCh, CURLOPT_HEADER, true);
     $response = curl_exec($curlCh);
     do {
         list($header, $response) = explode("\r\n\r\n", $response, 2);
     } while (PKPString::regexp_match('#HTTP/.*100#', $header));
     // Check whether we got a tar file.
     if (PKPString::regexp_match('#Content-Type: application/x-gtar#', $header)) {
         // Save the data to a temporary file.
         $tempfile = tempnam(sys_get_temp_dir(), 'tst');
         file_put_contents($tempfile, $response);
         // Recursively extract tar file.
         $result = $this->extractTarFile($tempfile);
         unlink($tempfile);
     } else {
         $matches = null;
         PKPString::regexp_match_get('#filename="([^"]+)"#', $header, $matches);
         self::assertTrue(isset($matches[1]));
         $result = array($matches[1] => $response);
     }
     // Destroy HTTP session.
     curl_close($curlCh);
     unlink($cookies);
     return $result;
 }
All Usage Examples Of PKPString::regexp_match_get