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


PHP sscanf函数代码示例

本文整理汇总了PHP中sscanf函数的典型用法代码示例。如果您正苦于以下问题:PHP sscanf函数的具体用法?PHP sscanf怎么用?PHP sscanf使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


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

示例1: authorize

 public function authorize(HeaderInterface $authHeader)
 {
     list($jwt) = sscanf($authHeader->toString(), 'Authorization: Bearer %s');
     if ($jwt) {
         try {
             /*
              * decode the jwt using the key from config
              */
             $secretKey = base64_decode($this->config->get('jwt')->get('key'));
             $this->token = JWT::decode($jwt, $secretKey, [$this->config->get('jwt')->get('algorithm')]);
             $this->isAuthorized = true;
             $this->response = Response::createMessage("10");
         } catch (Exception $e) {
             /*
              * the token was not able to be decoded.
              * this is likely because the signature was not able to be verified (tampered token)
              */
             $this->isAuthorized = false;
             $this->response = Response::createMessage("03");
             $this->response["data"] = $jwt;
         }
     } else {
         /*
          * No token was able to be extracted from the authorization header
          */
         $this->isAuthorized = false;
         $this->response = Response::createMessage("01");
     }
 }
开发者ID:kbokdia,项目名称:DemoProject,代码行数:29,代码来源:Request.php

示例2: get_product

function get_product($url, $page = 0)
{
    global $save_folder;
    $html = curl_get($url);
    //Загружает страницу товара
    $dom = str_get_html($html);
    $article = $dom->find('article', 0);
    //Берем артикул
    $str = $article->attr['id'];
    sscanf($str, 'post-%d', $art);
    $scripts = $dom->find('script');
    foreach ($scripts as $script) {
        if (strpos($script->src, "script.js")) {
            $str = "script[src='" . $script->src . "']";
        }
    }
    $dom->find($str, 0)->outertext = '';
    //Ajax запрос
    $html = get_ajax($art);
    //Получили данные из ajax
    $dom2 = str_get_html($html);
    //Ищем в 1-й странице div куда будем вставлять данные из ajax
    $dom->find('div[id=order-variables]', 0)->innertext = $dom2;
    //Сохраняем HTML
    file_put_contents($save_folder . 'product--' . $page . '.html', $dom);
}
开发者ID:Lyoshka,项目名称:evseeva.loc,代码行数:26,代码来源:index.php

示例3: store

 public static function store()
 {
     self::check_logged_in(array("asiakas", "tyontekija", "johtaja"));
     $params = $_POST;
     $palvelu = Palvelu::find($params['palvelu_id']);
     $aloitusaika = strtotime($params['paiva'] . ' ' . $params['kellonaika']);
     list($tunnit, $minuutit, $sekunnit) = sscanf($palvelu->kesto, '%d:%d:%d');
     $kesto = new DateInterval(sprintf('PT%dH%dM', $tunnit, $minuutit));
     $lopetusaika = date_timestamp_get(date_add(new DateTime('@' . $aloitusaika), $kesto));
     $attributes = array('asiakas_id' => $params['asiakas_id'], 'palvelu_id' => $params['palvelu_id'], 'tyontekija_id' => $params['tyontekija_id'], 'toimitila_id' => $params['toimitila_id'], 'aloitusaika' => date('Y-m-d H:i', $aloitusaika), 'lopetusaika' => date('Y-m-d H:i', $lopetusaika), 'on_peruutettu' => NULL);
     $varaus = new Varaus($attributes);
     $errors = $varaus->errors();
     // tarkistetaan resurssien ja asiakkaan saatavuus varausajalle
     if (count($errors) == 0) {
         $errors = $varaus->check_overlaps();
     }
     if (count($errors) > 0) {
         $tyontekijat = Tyontekija::all();
         $palvelut = Palvelu::all();
         $toimitilat = Toimitila::all();
         $asiakkaat = Asiakas::all();
         View::make('varaus/varaus_lisaa.html', array('errors' => $errors, 'varaus' => $varaus, 'tyontekijat' => $tyontekijat, 'palvelut' => $palvelut, 'toimitilat' => $toimitilat, 'asiakkaat' => $asiakkaat));
     } else {
         $varaus->save();
         Redirect::to('/', array('message' => 'Varaus tallennettu.'));
     }
 }
开发者ID:pekoe09,项目名称:Tsoha-Bootstrap,代码行数:27,代码来源:varaus_controller.php

示例4: detectFormatDate

function detectFormatDate($date_a_convertir, $compl = "01")
{
    global $msg;
    if (preg_match("#\\d{4}-\\d{2}-\\d{2}#", $date_a_convertir)) {
        $date = $date_a_convertir;
    } else {
        if (preg_match(getDatePattern(), $date_a_convertir)) {
            $date = extraitdate($date_a_convertir);
        } elseif (preg_match(getDatePattern("short"), $date_a_convertir)) {
            $format = str_replace("%", "", $msg["format_date_short"]);
            $format = str_replace("-", "", $format);
            $format = str_replace("/", "", $format);
            $format = str_replace("\\", "", $format);
            $format = str_replace(".", "", $format);
            $format = str_replace(" ", "", $format);
            $format = str_replace($msg["format_date_input_separator"], "", $format);
            list($date[substr($format, 0, 1)], $date[substr($format, 1, 1)], $date[substr($format, 2, 1)]) = sscanf($date_a_convertir, $msg["format_date_short_input"]);
            if ($date['Y'] && $date['m']) {
                $date = sprintf("%04d-%02s-%02s", $date['Y'], $date['m'], $compl);
            } else {
                $date = "0000-00-00";
            }
        } elseif (preg_match(getDatePattern("year"), $date_a_convertir, $matches)) {
            $date = $matches[0] . "-" . $compl . "-" . $compl;
        } else {
            $date = "0000-00-00";
        }
    }
    return $date;
}
开发者ID:bouchra012,项目名称:PMB,代码行数:30,代码来源:divers.inc.php

示例5: beautify

 /**
  * Beautifes a range label and returns the pretty result.
  *
  * @param string $value The range string. This must be in either a '$min-$max' format
  *                      a '$min+' format.
  * @return string The pretty range label.
  */
 public function beautify($value)
 {
     // if there's more than one element, handle as a range w/ an upper bound
     if (strpos($value, "-") !== false) {
         // get the range
         sscanf($value, "%d - %d", $lowerBound, $upperBound);
         // if the lower bound is the same as the upper bound make sure the singular label
         // is used
         if ($lowerBound == $upperBound) {
             return $this->getSingleUnitLabel($value, $lowerBound);
         } else {
             return $this->getRangeLabel($value, $lowerBound, $upperBound);
         }
     } else {
         // get the lower bound
         sscanf($value, "%d", $lowerBound);
         if ($lowerBound !== NULL) {
             $plusEncoded = urlencode('+');
             $plusLen = strlen($plusEncoded);
             $len = strlen($value);
             // if the label doesn't end with a '+', append it
             if ($len < $plusLen || substr($value, $len - $plusLen) != $plusEncoded) {
                 $value .= $plusEncoded;
             }
             return $this->getUnboundedLabel($value, $lowerBound);
         } else {
             // if no lower bound can be found, this isn't a valid range. in this case
             // we assume its a translation key and try to translate it.
             return Piwik_Translate(trim($value));
         }
     }
 }
开发者ID:neolf,项目名称:PIWIK4MOBILE,代码行数:39,代码来源:BeautifyRangeLabels.php

示例6: formatPhone

function formatPhone($phone)
{
    if (empty($phone)) {
        return "";
    }
    if (strlen($phone) == 7) {
        sscanf($phone, "%3s%4s", $prefix, $exchange);
    } else {
        if (strlen($phone) == 10) {
            sscanf($phone, "%3s%3s%4s", $area, $prefix, $exchange);
        } else {
            if (strlen($phone) > 10) {
                if (substr($phone, 0, 1) == '1') {
                    sscanf($phone, "%1s%3s%3s%4s", $country, $area, $prefix, $exchange);
                } else {
                    sscanf($phone, "%3s%3s%4s%s", $area, $prefix, $exchange, $extension);
                }
            } else {
                return "unknown phone format: {$phone}";
            }
        }
    }
    $out = "";
    $out .= isset($country) ? $country . ' ' : '';
    $out .= isset($area) ? '(' . $area . ') ' : '';
    $out .= $prefix . '-' . $exchange;
    $out .= isset($extension) ? ' x' . $extension : '';
    return $out;
}
开发者ID:jankichaudhari,项目名称:yii-site,代码行数:29,代码来源:phoneformat.php

示例7: process

 /**
  * Processes cell value
  *
  * @param   var in
  * @return  var
  * @throws  lang.FormatException
  */
 public function process($in)
 {
     if (1 !== sscanf($in, '%f', $out)) {
         throw new \lang\FormatException('Cannot parse "' . $in . '" into an double');
     }
     return $this->proceed($out);
 }
开发者ID:xp-framework,项目名称:csv,代码行数:14,代码来源:AsDouble.class.php

示例8: hydrate

 public function hydrate(RawObject $raw_object)
 {
     $commit = new Commit();
     $commit->setSha($raw_object->getSha());
     list($meta, $message) = explode("\n\n", $raw_object->getData());
     $commit->setMessage($message);
     foreach (explode("\n", $meta) as $meta_line) {
         sscanf($meta_line, "%s ", $attribute);
         $attribute_value = substr($meta_line, strlen($attribute) + 1);
         switch ($attribute) {
             case 'tree':
                 $commit->setTree(new TreeProxy($this->repo, $attribute_value));
                 break;
             case 'parent':
                 $commit->addParent(new CommitProxy($this->repo, $attribute_value));
                 break;
             case 'author':
                 preg_match('/(.*?) <(.*?)> ([0-9]*)( (.+))?/', $attribute_value, $matches);
                 $commit->setAuthor(new User($matches[1], $matches[2]));
                 $commit->setAuthorTime(\DateTime::createFromFormat('U O', $matches[3] . ' ' . $matches[5]));
                 break;
             case 'committer':
                 preg_match('/(.*?) <(.*?)> ([0-9]*)( (.+))?/', $attribute_value, $matches);
                 $commit->setCommitter(new User($matches[1], $matches[2]));
                 $commit->setCommitTime(\DateTime::createFromFormat('U O', $matches[3] . ' ' . $matches[5]));
                 break;
         }
     }
     return $commit;
 }
开发者ID:e-butik,项目名称:gittern,代码行数:30,代码来源:CommitHydrator.php

示例9: initTables

 /**
  * @throws SQLException
  * @return void
  */
 protected function initTables()
 {
     include_once 'creole/drivers/pgsql/metadata/PgSQLTableInfo.php';
     // Get Database Version
     // TODO: www.php.net/pg_version
     $result = pg_query($this->conn->getResource(), "SELECT version() as ver");
     if (!$result) {
         throw new SQLException("Failed to select database version");
     }
     // if (!$result)
     $row = pg_fetch_assoc($result, 0);
     $arrVersion = sscanf($row['ver'], '%*s %d.%d');
     $version = sprintf("%d.%d", $arrVersion[0], $arrVersion[1]);
     // Clean up
     $arrVersion = null;
     $row = null;
     pg_free_result($result);
     $result = null;
     $result = pg_query($this->conn->getResource(), "SELECT c.oid, \n\t\t\t\t\t\t\t\t\t\t\t\t\t\tcase when n.nspname='public' then c.relname else n.nspname||'.'||c.relname end as relname \n\t\t\t\t\t\t\t\t\t\t\t\t\t\tFROM pg_class c join pg_namespace n on (c.relnamespace=n.oid)\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tWHERE c.relkind = 'r'\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t  AND n.nspname NOT IN ('information_schema','pg_catalog')\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t  AND n.nspname NOT LIKE 'pg_temp%'\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t  AND n.nspname NOT LIKE 'pg_toast%'\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tORDER BY relname");
     if (!$result) {
         throw new SQLException("Could not list tables", pg_last_error($this->dblink));
     }
     while ($row = pg_fetch_assoc($result)) {
         $this->tables[strtoupper($row['relname'])] = new PgSQLTableInfo($this, $row['relname'], $version, $row['oid']);
     }
     $this->tablesLoaded = true;
 }
开发者ID:Daniel-Marynicz,项目名称:symfony1-legacy,代码行数:31,代码来源:PgSQLDatabaseInfo.php

示例10: parseNumberValue

 /**
  * Parse a string of the form "number unit" where unit is optional. The
  * results are stored in the $number and $unit parameters. Returns an
  * error code.
  * @param $value string to parse
  * @param $number call-by-ref parameter that will be set to the numerical value
  * @param $unit call-by-ref parameter that will be set to the "unit" string (after the number)
  * @return integer 0 (no errors), 1 (no number found at all), 2 (number
  * too large for this platform)
  */
 protected static function parseNumberValue($value, &$number, &$unit)
 {
     // Parse to find $number and (possibly) $unit
     $decseparator = NumberFormatter::getInstance()->getDecimalSeparatorForContentLanguage();
     $kiloseparator = NumberFormatter::getInstance()->getThousandsSeparatorForContentLanguage();
     $parts = preg_split('/([-+]?\\s*\\d+(?:\\' . $kiloseparator . '\\d\\d\\d)*' . '(?:\\' . $decseparator . '\\d+)?\\s*(?:[eE][-+]?\\d+)?)/u', trim(str_replace(array('&nbsp;', '&#160;', '&thinsp;', ' '), '', $value)), 2, PREG_SPLIT_DELIM_CAPTURE);
     if (count($parts) >= 2) {
         $numstring = str_replace($kiloseparator, '', preg_replace('/\\s*/u', '', $parts[1]));
         // simplify
         if ($decseparator != '.') {
             $numstring = str_replace($decseparator, '.', $numstring);
         }
         list($number) = sscanf($numstring, "%f");
         if (count($parts) >= 3) {
             $unit = self::normalizeUnit($parts[2]);
         }
     }
     if (count($parts) == 1 || $numstring === '') {
         // no number found
         return 1;
     } elseif (is_infinite($number)) {
         // number is too large for this platform
         return 2;
     } else {
         return 0;
     }
 }
开发者ID:whysasse,项目名称:kmwiki,代码行数:37,代码来源:SMW_DV_Number.php

示例11: isGd

	/**
	 * Returns whether image manipulations will be performed using GD or not.
	 *
	 * @return bool|null
	 */
	public function isGd()
	{
		if ($this->_isGd === null)
		{
			if (craft()->config->get('imageDriver') == 'gd')
			{
				$this->_isGd = true;
			}
			else if (extension_loaded('imagick'))
			{
				// Taken from Imagick\Imagine() constructor.
				$imagick = new \Imagick();
				$v = $imagick->getVersion();
				list($version, $year, $month, $day, $q, $website) = sscanf($v['versionString'], 'ImageMagick %s %04d-%02d-%02d %s %s');

				// Update this if Imagine updates theirs.
				if (version_compare('6.2.9', $version) <= 0)
				{
					$this->_isGd = false;
				}
				else
				{
					$this->_isGd = true;
				}
			}
			else
			{
				$this->_isGd = true;
			}
		}

		return $this->_isGd;
	}
开发者ID:harish94,项目名称:Craft-Release,代码行数:38,代码来源:ImagesService.php

示例12: locate

 /**
  * Find named pipe
  *
  * @return  string or NULL if no file can be found
  */
 protected function locate()
 {
     $pipes = '\\\\.\\pipe\\';
     // Check well-known pipe name
     if (file_exists($pipes . 'mysql')) {
         return $pipes . 'mysql';
     }
     // Locate my.ini in %WINDIR%, C: or the MySQL install dir, the latter of
     // which we determine by querying the registry using the "REG" tool.
     do {
         foreach ([getenv('WINDIR'), 'C:'] as $location) {
             $ini = new File($location, 'my.ini');
             if ($ini->exists()) {
                 break 2;
             }
         }
         exec('reg query "HKLM\\SOFTWARE\\MySQL AB" /s /e /f Location', $out, $ret);
         if (0 === $ret && 1 === sscanf($out[2], "    Location    REG_SZ    %[^\r]", $location)) {
             $ini = new File($location, 'my.ini');
             break;
         }
         return null;
     } while (0);
     $options = $this->parse($ini);
     return isset($options['client']['socket']) ? $pipes . $options['client']['socket'] : null;
 }
开发者ID:xp-framework,项目名称:rdbms,代码行数:31,代码来源:NamedPipe.class.php

示例13: get_mem_usage

function get_mem_usage()
{
    global $free_memory, $total_memory;
    $file = fopen('/proc/meminfo', 'r');
    if (FALSE === $file) {
        return -1;
    }
    $type = '';
    $val = 0;
    $unit = '';
    while (!feof($file)) {
        $line = fgets($file);
        sscanf($line, "%s%d%s", $type, $val, $unit);
        if (stristr($type, 'MemTotal') !== false) {
            $total_memory = $val;
        } else {
            if (stristr($type, 'MemFree') !== false) {
                $free_memory += $val;
            } else {
                if (stristr($type, 'Buffers') !== false) {
                    $free_memory += $val;
                } else {
                    if (stristr($type, 'Cached') !== false) {
                        $free_memory += $val;
                    }
                }
            }
        }
    }
    fclose($file);
}
开发者ID:thezawad,项目名称:bashu-onlinejudge,代码行数:31,代码来源:ajax_usage.php

示例14: getPolygons

 /**
  *
  */
 private function getPolygons()
 {
     $output = [];
     $matches = explode('endfacet', $this->raw);
     foreach ($matches as $match) {
         $output[] = sscanf($match, '  facet normal %s %s %s
         outer loop
           vertex   %s %s %s
           vertex   %s %s %s
           vertex   %s %s %s
         endloop
       endfacet');
     }
     array_shift($output);
     if (!is_array($output)) {
         return false;
     }
     array_walk($output, function (&$value) {
         if (!is_array($value)) {
             return false;
         }
         array_walk($value, function (&$item) {
             $item = pack('l', $item);
         });
         $this->polygons[] = $this->createPolygon(implode('', $value) . "");
     });
 }
开发者ID:fuding,项目名称:Wheatstone,代码行数:30,代码来源:AsciiSTL.php

示例15: deleteMultiple

 public function deleteMultiple(array $quads)
 {
     $response = $this->doRequest(self::URL_DELETE, json_encode($quads));
     $result = $response->json();
     list($count) = sscanf($result['result'], 'Successfully deleted %d triples.');
     return $count;
 }
开发者ID:pombredanne,项目名称:php-cayley,代码行数:7,代码来源:Client.php


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