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


PHP Stdlib\StringUtils类代码示例

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


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

示例1: getUtf8StringWrapper

 /**
  * Get the string wrapper supporting UTF-8 character encoding
  *
  * @return StringWrapperInterface
  */
 public function getUtf8StringWrapper()
 {
     if (!$this->utf8StringWrapper) {
         $this->utf8StringWrapper = StringUtils::getWrapper('UTF-8');
     }
     return $this->utf8StringWrapper;
 }
开发者ID:Flesh192,项目名称:magento,代码行数:12,代码来源:Code128.php

示例2: filter

 /**
  * Defined by Zend\Filter\Filter
  *
  * @param  string $value
  * @return string
  */
 public function filter($value)
 {
     // a unicode safe way of converting characters to \x00\x00 notation
     $pregQuotedSeparator = preg_quote($this->separator, '#');
     if (StringUtils::hasPcreUnicodeSupport()) {
         $patterns = array('#(' . $pregQuotedSeparator . ')(\\p{L}{1})#u', '#(^\\p{Ll}{1})#u');
         if (!extension_loaded('mbstring')) {
             $replacements = array(function ($matches) {
                 return strtoupper($matches[2]);
             }, function ($matches) {
                 return strtoupper($matches[1]);
             });
         } else {
             $replacements = array(function ($matches) {
                 return mb_strtoupper($matches[2], 'UTF-8');
             }, function ($matches) {
                 return mb_strtoupper($matches[1], 'UTF-8');
             });
         }
     } else {
         $patterns = array('#(' . $pregQuotedSeparator . ')([A-Za-z]{1})#', '#(^[A-Za-z]{1})#');
         $replacements = array(function ($matches) {
             return strtoupper($matches[2]);
         }, function ($matches) {
             return strtoupper($matches[1]);
         });
     }
     $filtered = $value;
     foreach ($patterns as $index => $pattern) {
         $filtered = preg_replace_callback($pattern, $replacements[$index], $filtered);
     }
     return $filtered;
 }
开发者ID:eltondias,项目名称:Relogio,代码行数:39,代码来源:SeparatorToCamelCase.php

示例3: setUp

 public function setUp()
 {
     if (!StringUtils::hasPcreUnicodeSupport()) {
         return $this->markTestSkipped('PCRE is not compiled with Unicode support');
     }
     $this->reflection = new ReflectionProperty('Zend\\Stdlib\\StringUtils', 'hasPcreUnicodeSupport');
     $this->reflection->setAccessible(true);
     $this->reflection->setValue(false);
 }
开发者ID:pnaq57,项目名称:zf2demo,代码行数:9,代码来源:CamelCaseToSeparatorNoPcreUnicodeTest.php

示例4: validateLength

 /**
  * Validator callback for new group name - check length if necessary
  *
  * @param string $value
  * @param array $context
  * @param integer $min
  * @param integer $max
  * @return bool
  * @internal
  */
 public function validateLength($value, $context, $min, $max)
 {
     if ($context['Where'] == 'new') {
         $length = \Zend\Stdlib\StringUtils::getWrapper('UTF-8')->strlen($value);
         $result = ($length >= $min and $length <= $max);
     } else {
         $result = true;
         // Field is ignored for existing groups
     }
     return $result;
 }
开发者ID:hschletz,项目名称:braintacle,代码行数:21,代码来源:AddToGroup.php

示例5: filter

 /**
  * Defined by Zend\Filter\Filter
  *
  * @param  string $value
  * @return string
  */
 public function filter($value)
 {
     if (StringUtils::hasPcreUnicodeSupport()) {
         $pattern = array('#(?<=(?:\\p{Lu}))(\\p{Lu}\\p{Ll})#', '#(?<=(?:\\p{Ll}|\\p{Nd}))(\\p{Lu})#');
         $replacement = array($this->separator . '\\1', $this->separator . '\\1');
     } else {
         $pattern = array('#(?<=(?:[A-Z]))([A-Z]+)([A-Z][a-z])#', '#(?<=(?:[a-z0-9]))([A-Z])#');
         $replacement = array('\\1' . $this->separator . '\\2', $this->separator . '\\1');
     }
     return preg_replace($pattern, $replacement, $value);
 }
开发者ID:eltondias,项目名称:Relogio,代码行数:17,代码来源:CamelCaseToSeparator.php

示例6: getWrapper

 /**
  * Get string wrapper
  *
  * @param string $encoding
  *
  * @return StringWrapperInterface
  */
 public function getWrapper($encoding = '')
 {
     $encoding = strtoupper($encoding ?: Pi::config('charset'));
     if (!isset($this->stringWrapper[$encoding])) {
         try {
             $stringWrapper = StringUtils::getWrapper(Pi::config('charset'));
         } catch (\Exception $e) {
             $stringWrapper = false;
         }
         $this->stringWrapper[$encoding] = $stringWrapper;
     }
     return $this->stringWrapper[$encoding];
 }
开发者ID:Andyyang1981,项目名称:pi,代码行数:20,代码来源:String.php

示例7: filter

 /**
  * Defined by Zend\Filter\FilterInterface
  *
  * Returns the string $value, removing all but digit characters
  *
  * @param  string $value
  * @return string
  */
 public function filter($value)
 {
     if (!StringUtils::hasPcreUnicodeSupport()) {
         // POSIX named classes are not supported, use alternative 0-9 match
         $pattern = '/[^0-9]/';
     } elseif (extension_loaded('mbstring')) {
         // Filter for the value with mbstring
         $pattern = '/[^[:digit:]]/';
     } else {
         // Filter for the value without mbstring
         $pattern = '/[\\p{^N}]/';
     }
     return preg_replace($pattern, '', (string) $value);
 }
开发者ID:razvansividra,项目名称:pnlzf2-1,代码行数:22,代码来源:Digits.php

示例8: filter

 /**
  * Defined by Zend\Filter\Filter
  *
  * @param  string|array $value
  * @return string|array
  */
 public function filter($value)
 {
     if (!is_scalar($value) && !is_array($value)) {
         return $value;
     }
     $value = parent::filter($value);
     $lowerCaseFirst = 'lcfirst';
     if (StringUtils::hasPcreUnicodeSupport() && extension_loaded('mbstring')) {
         $lowerCaseFirst = function ($value) {
             if (0 === mb_strlen($value)) {
                 return $value;
             }
             return mb_strtolower(mb_substr($value, 0, 1)) . mb_substr($value, 1);
         };
     }
     return is_array($value) ? array_map($lowerCaseFirst, $value) : call_user_func($lowerCaseFirst, $value);
 }
开发者ID:Flesh192,项目名称:magento,代码行数:23,代码来源:UnderscoreToStudlyCase.php

示例9: filter

 /**
  * Defined by Zend\Filter\FilterInterface
  *
  * Returns the string $value, removing all but digit characters
  *
  * If the value provided is non-scalar, the value will remain unfiltered
  * and an E_USER_WARNING will be raised indicating it's unfilterable.
  *
  * @param  string $value
  * @return string|mixed
  */
 public function filter($value)
 {
     if (null === $value) {
         return null;
     }
     if (!is_scalar($value)) {
         trigger_error(sprintf('%s expects parameter to be scalar, "%s" given; cannot filter', __METHOD__, is_object($value) ? get_class($value) : gettype($value)), E_USER_WARNING);
         return $value;
     }
     if (!StringUtils::hasPcreUnicodeSupport()) {
         // POSIX named classes are not supported, use alternative 0-9 match
         $pattern = '/[^0-9]/';
     } elseif (extension_loaded('mbstring')) {
         // Filter for the value with mbstring
         $pattern = '/[^[:digit:]]/';
     } else {
         // Filter for the value without mbstring
         $pattern = '/[\\p{^N}]/';
     }
     return preg_replace($pattern, '', (string) $value);
 }
开发者ID:idwsdta,项目名称:INIT-frame,代码行数:32,代码来源:Digits.php

示例10: getKeywords

 protected function getKeywords($string)
 {
     $innerPattern = StringUtils::hasPcreUnicodeSupport() ? '[^\\p{L}]' : '[^a-z0-9ßäöü ]';
     $pattern = '~' . $innerPattern . '~isu';
     $stripPattern = '~^' . $innerPattern . '+|' . $innerPattern . '+$~isu';
     $parts = array();
     $textParts = explode(' ', $string);
     foreach ($textParts as $part) {
         $part = strtolower(trim($part));
         $part = preg_replace($stripPattern, '', $part);
         if ('' == $part) {
             continue;
         }
         $parts[] = $part;
         $tmpPart = preg_replace($pattern, ' ', $part);
         if ($part != $tmpPart) {
             $tmpParts = explode(' ', $tmpPart);
             $tmpParts = array_filter($tmpParts);
             $parts = array_merge($parts, $tmpParts);
         }
     }
     return $parts;
 }
开发者ID:cross-solution,项目名称:yawik,代码行数:23,代码来源:PropertyToKeywords.php

示例11: isValid

 /**
  * Defined by Interface
  *
  * Returns true if and only if the $value is a valid hostname with respect to the current allow option
  *
  * @param  string $value
  * @return bool
  */
 public function isValid($value)
 {
     if (!is_string($value)) {
         $this->error(self::INVALID);
         return false;
     }
     $this->setValue($value);
     // Check input against IP address schema
     if ((preg_match('/^[0-9.]*$/', $value) && strpos($value, '.') !== false || preg_match('/^[0-9a-f:.]*$/i', $value) && strpos($value, ':') !== false) && $this->getIpValidator()->setTranslator($this->getTranslator())->isValid($value)) {
         if (!($this->getAllow() & self::ALLOW_IP)) {
             $this->error(self::IP_ADDRESS_NOT_ALLOWED);
             return false;
         }
         return true;
     }
     // Local hostnames are allowed to be partial (ending '.')
     if ($this->getAllow() & self::ALLOW_LOCAL) {
         if (substr($value, -1) === '.') {
             $value = substr($value, 0, -1);
             if (substr($value, -1) === '.') {
                 // Empty hostnames (ending '..') are not allowed
                 $this->error(self::INVALID_LOCAL_NAME);
                 return false;
             }
         }
     }
     $domainParts = explode('.', $value);
     // Prevent partial IP V4 addresses (ending '.')
     if (count($domainParts) == 4 && preg_match('/^[0-9.a-e:.]*$/i', $value) && $this->getIpValidator()->setTranslator($this->getTranslator())->isValid($value)) {
         $this->error(self::INVALID_LOCAL_NAME);
     }
     $utf8StrWrapper = StringUtils::getWrapper('UTF-8');
     // Check input against DNS hostname schema
     if (count($domainParts) > 1 && $utf8StrWrapper->strlen($value) >= 4 && $utf8StrWrapper->strlen($value) <= 254) {
         $status = false;
         do {
             // First check TLD
             $matches = [];
             if (preg_match('/([^.]{2,63})$/u', end($domainParts), $matches) || array_key_exists(end($domainParts), $this->validIdns)) {
                 reset($domainParts);
                 // Hostname characters are: *(label dot)(label dot label); max 254 chars
                 // label: id-prefix [*ldh{61} id-prefix]; max 63 chars
                 // id-prefix: alpha / digit
                 // ldh: alpha / digit / dash
                 // Match TLD against known list
                 $this->tld = strtoupper($matches[1]);
                 if ($this->getTldCheck()) {
                     if (!in_array(strtolower($this->tld), $this->validTlds) && !in_array($this->tld, $this->validTlds)) {
                         $this->error(self::UNKNOWN_TLD);
                         $status = false;
                         break;
                     }
                     // We have already validated that the TLD is fine. We don't want it to go through the below
                     // checks as new UTF-8 TLDs will incorrectly fail if there is no IDN regex for it.
                     array_pop($domainParts);
                 }
                 /**
                  * Match against IDN hostnames
                  * Note: Keep label regex short to avoid issues with long patterns when matching IDN hostnames
                  *
                  * @see Hostname\Interface
                  */
                 $regexChars = [0 => '/^[a-z0-9\\x2d]{1,63}$/i'];
                 if ($this->getIdnCheck() && isset($this->validIdns[$this->tld])) {
                     if (is_string($this->validIdns[$this->tld])) {
                         $regexChars += (include __DIR__ . '/' . $this->validIdns[$this->tld]);
                     } else {
                         $regexChars += $this->validIdns[$this->tld];
                     }
                 }
                 // Check each hostname part
                 $check = 0;
                 foreach ($domainParts as $domainPart) {
                     // Decode Punycode domain names to IDN
                     if (strpos($domainPart, 'xn--') === 0) {
                         $domainPart = $this->decodePunycode(substr($domainPart, 4));
                         if ($domainPart === false) {
                             return false;
                         }
                     }
                     // Check dash (-) does not start, end or appear in 3rd and 4th positions
                     if ($utf8StrWrapper->strpos($domainPart, '-') === 0 || $utf8StrWrapper->strlen($domainPart) > 2 && $utf8StrWrapper->strpos($domainPart, '-', 2) == 2 && $utf8StrWrapper->strpos($domainPart, '-', 3) == 3 || $utf8StrWrapper->strpos($domainPart, '-') === $utf8StrWrapper->strlen($domainPart) - 1) {
                         $this->error(self::INVALID_DASH);
                         $status = false;
                         break 2;
                     }
                     // Check each domain part
                     $checked = false;
                     foreach ($regexChars as $regexKey => $regexChar) {
                         $status = preg_match($regexChar, $domainPart);
                         if ($status > 0) {
                             $length = 63;
//.........这里部分代码省略.........
开发者ID:Alex--Jin,项目名称:homerapi,代码行数:101,代码来源:Hostname.php

示例12: importCsv

 public function importCsv($csv, User $user, $bankCode)
 {
     if ($csv['error'] != 0) {
         throw new \InvalidArgumentException('System has errors with uploaded file');
     }
     if (!$user) {
         return;
     }
     $counts = array(0, 0);
     if (($handle = fopen($csv['tmp_name'], 'r')) !== false) {
         // 			fgets($handle, 4096);
         $data = fgets($handle, 4096);
         $delimiter = ',';
         if (count(explode(';', $data)) > 8) {
             $delimiter = ';';
         }
         rewind($handle);
         $data = fgetcsv($handle, 4096, $delimiter);
         if (in_array($data[0], array('Konto', 'Kliendi konto'))) {
             $data = fgetcsv($handle, 4096, $delimiter);
         }
         rewind($handle);
         while (($data = fgetcsv($handle, 4096, $delimiter)) !== false) {
             if (in_array($data[0], array('Konto', 'Kliendi konto'))) {
                 continue;
             }
             if ($bankCode == BankTransaction::BANK_KREDIIDIPANK) {
                 //valjavote.csv
                 $name = StringUtils::getWrapper('ISO-8859-1', 'UTF-8')->convert(trim($data[14]));
                 $referenceNumber = trim($data[22]);
                 $sum = str_replace(',', '.', trim($data[3]));
                 $paymentDate = \DateTime::createFromFormat('d.m.Y', $data[0]);
                 $description = StringUtils::getWrapper('ISO-8859-1', 'UTF-8')->convert(trim($data[21]));
                 $archiveSign = StringUtils::getWrapper('ISO-8859-1', 'UTF-8')->convert(trim($data[1]));
                 $payerIban = StringUtils::getWrapper('ISO-8859-1', 'UTF-8')->convert(trim($data[16]));
             } elseif ($bankCode == BankTransaction::BANK_SEB) {
                 $name = StringUtils::getWrapper('ISO-8859-1', 'UTF-8')->convert(trim($data[4]));
                 $referenceNumber = trim($data[9]);
                 $sum = str_replace(',', '.', (trim($data[7] == 'D') ? -1 : 1) * trim(str_replace(',', '.', $data[8])));
                 $paymentDate = \DateTime::createFromFormat('d.m.Y', $data[2]);
                 $description = StringUtils::getWrapper('ISO-8859-1', 'UTF-8')->convert(trim($data[11]));
                 $archiveSign = StringUtils::getWrapper('ISO-8859-1', 'UTF-8')->convert(trim($data[10]));
                 $payerIban = StringUtils::getWrapper('ISO-8859-1', 'UTF-8')->convert(trim($data[3]));
             } elseif ($bankCode == BankTransaction::BANK_SWED) {
                 //toimingud.csv
                 $name = StringUtils::getWrapper('ISO-8859-1', 'UTF-8')->convert(trim($data[4]));
                 $referenceNumber = trim($data[9]);
                 $sum = str_replace(',', '.', trim($data[8]));
                 $paymentDate = \DateTime::createFromFormat('d-m-Y', $data[2]);
                 $description = StringUtils::getWrapper('ISO-8859-1', 'UTF-8')->convert(trim($data[11]));
                 $archiveSign = StringUtils::getWrapper('ISO-8859-1', 'UTF-8')->convert(trim($data[10]));
                 $payerIban = StringUtils::getWrapper('ISO-8859-1', 'UTF-8')->convert(trim($data[3]));
             } elseif ($bankCode == BankTransaction::BANK_NORDEA) {
                 $name = StringUtils::getWrapper('ISO-8859-1', 'UTF-8')->convert(trim($data[4]));
                 $referenceNumber = trim($data[7]);
                 $sum = str_replace(',', '.', (trim($data[5] == 'D') ? -1 : 1) * trim(str_replace(',', '.', $data[6])));
                 $paymentDate = \DateTime::createFromFormat('d.m.Y', $data[2]);
                 $description = StringUtils::getWrapper('ISO-8859-1', 'UTF-8')->convert(trim($data[9]));
                 $archiveSign = StringUtils::getWrapper('ISO-8859-1', 'UTF-8')->convert(trim($data[8]));
                 $payerIban = StringUtils::getWrapper('ISO-8859-1', 'UTF-8')->convert(trim($data[3]));
             }
             if ($name == null || $paymentDate === false) {
                 continue;
             }
             $paymentDate->setTime(0, 0, 0);
             if ($archiveSign !== null && $archiveSign !== '') {
                 $transaction = $this->entityManager->getRepository(BankTransaction::getClass())->findOneBy(array('name' => $name, 'referenceNumber' => $referenceNumber, 'sum' => $sum, 'paymentDate' => $paymentDate, 'description' => $description, 'archiveSign' => $archiveSign));
                 if ($transaction != null) {
                     continue;
                 }
             }
             $transaction = new BankTransaction();
             $transaction->setName($name);
             $transaction->setReferenceNumber($referenceNumber);
             $transaction->setSum($sum);
             $transaction->setType($sum < 0 ? BankTransaction::TYPE_OUTGOING : BankTransaction::TYPE_INCOMING);
             $transaction->setPaymentDate($paymentDate);
             $transaction->setDescription($description);
             $transaction->setArchiveSign($archiveSign);
             $transaction->setPayerIban($payerIban);
             $transaction->setPaymentType(BankTransaction::PAYMENT_TYPE_TRANSFER);
             $transaction->setUser($user);
             $this->saveTransaction($transaction);
             if ($sum > 0) {
                 $counts[1]++;
                 $this->autoAssociateIncoming($transaction);
             } else {
                 $counts[0]++;
             }
         }
         fclose($handle);
     }
     return $counts;
 }
开发者ID:kristjanAnd,项目名称:SimpleIV,代码行数:94,代码来源:BankService.php

示例13: encodeText

 /**
  * Encode a text to match console encoding
  *
  * @param  string $text
  * @return string the encoding text
  */
 public function encodeText($text)
 {
     if ($this->isUtf8()) {
         if (StringUtils::isValidUtf8($text)) {
             return $text;
         }
         return utf8_encode($text);
     }
     if (StringUtils::isValidUtf8($text)) {
         return utf8_decode($text);
     }
     return $text;
 }
开发者ID:Flesh192,项目名称:magento,代码行数:19,代码来源:AbstractAdapter.php

示例14: strPad

 /**
  * Pad a string to a certain length with another string
  *
  * @param  string  $input
  * @param  integer $padLength
  * @param  string  $padString
  * @param  integer $padType
  * @return string
  */
 public function strPad($input, $padLength, $padString = ' ', $padType = STR_PAD_RIGHT)
 {
     if (StringUtils::isSingleByteEncoding($this->getEncoding())) {
         return str_pad($input, $padLength, $padString, $padType);
     }
     $lengthOfPadding = $padLength - $this->strlen($input);
     if ($lengthOfPadding <= 0) {
         return $input;
     }
     $padStringLength = $this->strlen($padString);
     if ($padStringLength === 0) {
         return $input;
     }
     $repeatCount = floor($lengthOfPadding / $padStringLength);
     if ($padType === STR_PAD_BOTH) {
         $lastStringLeft = '';
         $lastStringRight = '';
         $repeatCountLeft = $repeatCountRight = ($repeatCount - $repeatCount % 2) / 2;
         $lastStringLength = $lengthOfPadding - 2 * $repeatCountLeft * $padStringLength;
         $lastStringLeftLength = $lastStringRightLength = floor($lastStringLength / 2);
         $lastStringRightLength += $lastStringLength % 2;
         $lastStringLeft = $this->substr($padString, 0, $lastStringLeftLength);
         $lastStringRight = $this->substr($padString, 0, $lastStringRightLength);
         return str_repeat($padString, $repeatCountLeft) . $lastStringLeft . $input . str_repeat($padString, $repeatCountRight) . $lastStringRight;
     }
     $lastString = $this->substr($padString, 0, $lengthOfPadding % $padStringLength);
     if ($padType === STR_PAD_LEFT) {
         return str_repeat($padString, $repeatCount) . $lastString . $input;
     }
     return $input . str_repeat($padString, $repeatCount) . $lastString;
 }
开发者ID:razvansividra,项目名称:pnlzf2-1,代码行数:40,代码来源:AbstractStringWrapper.php

示例15: getRegexComponents

 /**
  * Get all the regex components
  *
  * @return array
  */
 public function getRegexComponents()
 {
     if ($this->regexComponents == null) {
         $this->regexComponents[self::REGEX_NUMBERS] = '0-9';
         $this->regexComponents[self::REGEX_FLAGS] = '';
         if (StringUtils::hasPcreUnicodeSupport()) {
             $this->regexComponents[self::REGEX_NUMBERS] = '\\p{N}';
             $this->regexComponents[self::REGEX_FLAGS] .= 'u';
         }
     }
     return $this->regexComponents;
 }
开发者ID:leodido,项目名称:moneylaundry,代码行数:17,代码来源:Uncurrency.php


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