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


PHP Strings::replace方法代码示例

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


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

示例1: process

 /**
  * @param  string
  * @param  array
  * @return array of [sql, params]
  */
 public function process($sql, $params)
 {
     $this->params = $params;
     $this->counter = 0;
     $this->remaining = array();
     $this->arrayMode = 'assoc';
     $sql = Strings::replace($sql, '~\'.*?\'|".*?"|\\?|\\b(?:INSERT|REPLACE|UPDATE)\\b~si', array($this, 'callback'));
     while ($this->counter < count($params)) {
         $sql .= ' ' . $this->formatValue($params[$this->counter++]);
     }
     return array($sql, $this->remaining);
 }
开发者ID:riskatlas,项目名称:micka,代码行数:17,代码来源:SqlPreprocessor.php

示例2: write

    /**
     * Expands %node.word, %node.array, %node.args, %escape(), %modify(), %var, %raw in code.
     * @param  string
     * @return string
     */
    public function write($mask)
    {
        $args = func_get_args();
        array_shift($args);
        $word = strpos($mask, '%node.word') === FALSE ? NULL : $this->argsTokenizer->fetchWord();
        $me = $this;
        $mask = Strings::replace($mask, '#%escape(\\(([^()]*+|(?1))+\\))#', new Callback(create_function('$m', 'extract(NCFix::$vars[' . NCFix::uses(array('me' => $me)) . '], EXTR_REFS);
			return $me->escape(substr($m[1], 1, -1));
		')));
        $mask = Strings::replace($mask, '#%modify(\\(([^()]*+|(?1))+\\))#', new Callback(create_function('$m', 'extract(NCFix::$vars[' . NCFix::uses(array('me' => $me)) . '], EXTR_REFS);
			return $me->formatModifiers(substr($m[1], 1, -1));
		')));
        return Strings::replace($mask, '#([,+]\\s*)?%(node\\.word|node\\.array|node\\.args|var|raw)(\\?)?(\\s*\\+\\s*)?()#', new Callback(create_function('$m', 'extract(NCFix::$vars[' . NCFix::uses(array('me' => $me, 'word' => $word, 'args' => &$args)) . '], EXTR_REFS);
			list(, $l, $macro, $cond, $r) = $m;

			switch ($macro) {
			case \'node.word\':
				$code = $me->formatWord($word); break;
			case \'node.args\':
				$code = $me->formatArgs(); break;
			case \'node.array\':
				$code = $me->formatArray();
				$code = $cond && $code === \'array()\' ? \'\' : $code; break;
			case \'var\':
				$code = var_export(array_shift($args), TRUE); break;
			case \'raw\':
				$code = (string) array_shift($args); break;
			}

			if ($cond && $code === \'\') {
				return $r ? $l : $r;
			} else {
				return $l . $code . $r;
			}
		')));
    }
开发者ID:riskatlas,项目名称:micka,代码行数:41,代码来源:PhpWriter.php

示例3: createHttpRequest

 /**
  * Creates current HttpRequest object.
  * @return HttpRequest
  */
 public function createHttpRequest()
 {
     // DETECTS URI, base path and script path of the request.
     $url = new UrlScript();
     $url->scheme = !empty($_SERVER['HTTPS']) && strcasecmp($_SERVER['HTTPS'], 'off') ? 'https' : 'http';
     $url->user = isset($_SERVER['PHP_AUTH_USER']) ? $_SERVER['PHP_AUTH_USER'] : '';
     $url->password = isset($_SERVER['PHP_AUTH_PW']) ? $_SERVER['PHP_AUTH_PW'] : '';
     // host & port
     if (isset($_SERVER['HTTP_HOST'])) {
         $pair = explode(':', $_SERVER['HTTP_HOST']);
     } elseif (isset($_SERVER['SERVER_NAME'])) {
         $pair = explode(':', $_SERVER['SERVER_NAME']);
     } else {
         $pair = array('');
     }
     $url->host = preg_match('#^[-._a-z0-9]+$#', $pair[0]) ? $pair[0] : '';
     if (isset($pair[1])) {
         $url->port = (int) $pair[1];
     } elseif (isset($_SERVER['SERVER_PORT'])) {
         $url->port = (int) $_SERVER['SERVER_PORT'];
     }
     // path & query
     if (isset($_SERVER['REQUEST_URI'])) {
         // Apache, IIS 6.0
         $requestUrl = $_SERVER['REQUEST_URI'];
     } elseif (isset($_SERVER['ORIG_PATH_INFO'])) {
         // IIS 5.0 (PHP as CGI ?)
         $requestUrl = $_SERVER['ORIG_PATH_INFO'];
         if (isset($_SERVER['QUERY_STRING']) && $_SERVER['QUERY_STRING'] != '') {
             $requestUrl .= '?' . $_SERVER['QUERY_STRING'];
         }
     } else {
         $requestUrl = '';
     }
     $requestUrl = Strings::replace($requestUrl, $this->urlFilters['url']);
     $tmp = explode('?', $requestUrl, 2);
     $url->path = Strings::replace($tmp[0], $this->urlFilters['path']);
     $url->query = isset($tmp[1]) ? $tmp[1] : '';
     // normalized url
     $url->canonicalize();
     $url->path = Strings::fixEncoding($url->path);
     // detect script path
     if (isset($_SERVER['SCRIPT_NAME'])) {
         $script = $_SERVER['SCRIPT_NAME'];
     } elseif (isset($_SERVER['DOCUMENT_ROOT'], $_SERVER['SCRIPT_FILENAME']) && strncmp($_SERVER['DOCUMENT_ROOT'], $_SERVER['SCRIPT_FILENAME'], strlen($_SERVER['DOCUMENT_ROOT'])) === 0) {
         $script = '/' . ltrim(strtr(substr($_SERVER['SCRIPT_FILENAME'], strlen($_SERVER['DOCUMENT_ROOT'])), '\\', '/'), '/');
     } else {
         $script = '/';
     }
     $path = strtolower($url->path) . '/';
     $script = strtolower($script) . '/';
     $max = min(strlen($path), strlen($script));
     for ($i = 0; $i < $max; $i++) {
         if ($path[$i] !== $script[$i]) {
             break;
         } elseif ($path[$i] === '/') {
             $url->scriptPath = substr($url->path, 0, $i + 1);
         }
     }
     // GET, POST, COOKIE
     $useFilter = !in_array(ini_get('filter.default'), array('', 'unsafe_raw')) || ini_get('filter.default_flags');
     parse_str($url->query, $query);
     if (!$query) {
         $query = $useFilter ? filter_input_array(INPUT_GET, FILTER_UNSAFE_RAW) : (empty($_GET) ? array() : $_GET);
     }
     $post = $useFilter ? filter_input_array(INPUT_POST, FILTER_UNSAFE_RAW) : (empty($_POST) ? array() : $_POST);
     $cookies = $useFilter ? filter_input_array(INPUT_COOKIE, FILTER_UNSAFE_RAW) : (empty($_COOKIE) ? array() : $_COOKIE);
     $gpc = (bool) get_magic_quotes_gpc();
     $old = error_reporting(error_reporting() ^ E_NOTICE);
     // remove fucking quotes and check (and optionally convert) encoding
     if ($gpc || $this->encoding) {
         $utf = strcasecmp($this->encoding, 'UTF-8') === 0;
         $list = array(&$query, &$post, &$cookies);
         while (list($key, $val) = each($list)) {
             foreach ($val as $k => $v) {
                 unset($list[$key][$k]);
                 if ($gpc) {
                     $k = stripslashes($k);
                 }
                 if ($this->encoding && is_string($k) && (preg_match(self::NONCHARS, $k) || preg_last_error())) {
                     // invalid key -> ignore
                 } elseif (is_array($v)) {
                     $list[$key][$k] = $v;
                     $list[] =& $list[$key][$k];
                 } else {
                     if ($gpc && !$useFilter) {
                         $v = stripSlashes($v);
                     }
                     if ($this->encoding) {
                         if ($utf) {
                             $v = Strings::fixEncoding($v);
                         } else {
                             if (!Strings::checkEncoding($v)) {
                                 $v = iconv($this->encoding, 'UTF-8//IGNORE', $v);
                             }
                             $v = html_entity_decode($v, ENT_QUOTES, 'UTF-8');
//.........这里部分代码省略.........
开发者ID:riskatlas,项目名称:micka,代码行数:101,代码来源:RequestFactory.php

示例4: macroOldAttr

 /**
  * {attr ...}
  * @deprecated
  */
 public function macroOldAttr(MacroNode $node)
 {
     return Strings::replace($node->args . ' ', '#\\)\\s+#', ')->');
 }
开发者ID:riskatlas,项目名称:micka,代码行数:8,代码来源:CoreMacros.php

示例5: dump

 public static function dump($sql)
 {
     $keywords1 = 'CREATE\\s+TABLE|CREATE(?:\\s+UNIQUE)?\\s+INDEX|SELECT|UPDATE|INSERT(?:\\s+INTO)?|REPLACE(?:\\s+INTO)?|DELETE|FROM|WHERE|HAVING|GROUP\\s+BY|ORDER\\s+BY|LIMIT|SET|VALUES|LEFT\\s+JOIN|INNER\\s+JOIN|TRUNCATE';
     $keywords2 = 'ALL|DISTINCT|DISTINCTROW|AS|USING|ON|AND|OR|IN|IS|NOT|NULL|LIKE|TRUE|FALSE|INTEGER|CLOB|VARCHAR|DATETIME|TIME|DATE|INT|SMALLINT|BIGINT|BOOL|BOOLEAN|DECIMAL|FLOAT|TEXT|VARCHAR|DEFAULT|AUTOINCREMENT|PRIMARY\\s+KEY';
     // insert new lines
     $sql = " {$sql} ";
     $sql = self::replace($sql, "#(?<=[\\s,(])({$keywords1})(?=[\\s,)])#", "\n\$1");
     if (strpos($sql, "CREATE TABLE") !== FALSE) {
         $sql = Strings::replace($sql, "#,\\s+#i", ", \n");
     }
     // reduce spaces
     $sql = self::replace($sql, '#[ \\t]{2,}#', " ");
     $sql = wordwrap($sql, 100);
     $sql = htmlSpecialChars($sql);
     $sql = self::replace($sql, "#([ \t]*\r?\n){2,}#", "\n");
     $sql = self::replace($sql, "#VARCHAR\\(#", "VARCHAR (");
     // syntax highlight
     $sql = self::replace($sql, "#(/\\*.+?\\*/)|(\\*\\*.+?\\*\\*)|(?<=[\\s,(])({$keywords1})(?=[\\s,)])|(?<=[\\s,(=])({$keywords2})(?=[\\s,)=])#s", function ($matches) {
         if (!empty($matches[1])) {
             // comment
             return '<em style="color:gray">' . $matches[1] . '</em>';
         }
         if (!empty($matches[2])) {
             // error
             return '<strong style="color:red">' . $matches[2] . '</strong>';
         }
         if (!empty($matches[3])) {
             // most important keywords
             return '<strong style="color:blue">' . $matches[3] . '</strong>';
         }
         if (!empty($matches[4])) {
             // other keywords
             return '<strong style="color:green">' . $matches[4] . '</strong>';
         }
     });
     $sql = trim($sql);
     return '<pre class="dump">' . $sql . "</pre>\n";
 }
开发者ID:mnohosten,项目名称:yesorm,代码行数:38,代码来源:YesPanel.php

示例6: wp_get_attachment_image_src

        return $id;
    }
    return wp_get_attachment_image_src($post->ID, $size)[0];
};
MangoFilters::$set['wp_thumbnail'] = function ($id, $size = 'thumbnail') {
    $post = lazy_post($id);
    if (!$post) {
        return $id;
    }
    return wp_get_attachment_image_src(get_post_thumbnail_id($post->ID), $size)[0];
};
MangoFilters::$set['wp_esc'] = function ($str) {
    return html_entity_decode($str);
};
MangoFilters::$set['number'] = function ($number, $decimal = 2) {
    if (fmod($number, 1) == 0) {
        $decimal = 0;
    }
    $sep = '.';
    $formatted = number_format($number, $decimal, $sep, ",");
    if ($decimal) {
        $formatted = Strings::replace($formatted, '~\\.?0$~');
    }
    return $formatted;
};
function nbsp($str)
{
    $str = trim($str);
    return Nette\Utils\Strings::replace($str, '~[ ]~', " ");
}
MangoFilters::$set['nbsp'] = 'nbsp';
开发者ID:manGoweb,项目名称:MangoPressTemplating,代码行数:31,代码来源:filters.php

示例7: indent

    /**
     * Indents the HTML content from the left.
     * @param  string UTF-8 encoding or 8-bit
     * @param  int
     * @param  string
     * @return string
     */
    public static function indent($s, $level = 1, $chars = "\t")
    {
        if ($level >= 1) {
            $s = Strings::replace($s, '#<(textarea|pre).*?</\\1#si', new Callback(create_function('$m', '
				return strtr($m[0], " \\t\\r\\n", "\\x1F\\x1E\\x1D\\x1A");
			')));
            $s = Strings::indent($s, $level, $chars);
            $s = strtr($s, "", " \t\r\n");
        }
        return $s;
    }
开发者ID:riskatlas,项目名称:micka,代码行数:18,代码来源:Helpers.php

示例8: buildText

 /**
  * Builds text content.
  * @return void
  */
 protected function buildText()
 {
     $text = $this->getBody();
     if ($text instanceof ITemplate) {
         $text->mail = $this;
         $this->setBody($text->__toString(TRUE));
     } elseif ($text == NULL && $this->html != NULL) {
         // intentionally ==
         $text = Strings::replace($this->html, array('#<(style|script|head).*</\\1>#Uis' => '', '#<t[dh][ >]#i' => " \$0", '#[\\r\\n]+#' => ' ', '#<(/?p|/?h\\d|li|br|/tr)[ >/]#i' => "\n\$0"));
         $text = html_entity_decode(strip_tags($text), ENT_QUOTES, 'UTF-8');
         $text = Strings::replace($text, '#[ \\t]+#', ' ');
         $this->setBody(trim($text));
     }
 }
开发者ID:riskatlas,项目名称:micka,代码行数:18,代码来源:Message.php

示例9: flashRedirect

      if ($if) {
          $this->flashMessage($dobre, 'success');
      } else {
          $this->flashMessage($zle, 'danger');
      }
  }
  /** Funkcia pre zjednodusenie vypisu flash spravy a presmerovania
 * @param array|string $redirect Adresa presmerovania
 * @param string $text Text pre vypis hlasenia
 * @param string $druh - druh hlasenia
 */
  public function flashRedirect($redirect, $text = "", $druh = "info")
  {
      $this->flashMessage($text, $druh);
      if (is_array($redirect)) {
          if (count($redirect) > 1) {
              $this->redirect($redirect[0], $redirect[1]);
          } elseif (count($redirect) == 1) {
              $this->redirect($redirect[0]);
          }
      } else {
          $this->redirect($redirect);
      }
  }
  /**
 * Funkcia pre zjednodusenie vypisu flash spravy a presmerovania aj pre chybovy stav
 * @param boolean $ok Podmienka
 * @param array|string $redirect Adresa presmerovania
 * @param string $textOk Text pre vypis hlasenia ak je podmienka splnena
 * @param string $textEr Text pre vypis hlasenia ak NIE je podmienka splnena
 */
  public function flashOut($ok, $redirect, $textOk = "", $textEr = "")
  {
      if ($ok) {
          $this->flashRedirect($redirect, $textOk, "success");
      } else {
          $this->flashMessage($textEr, 'danger');
      }
  }
  /**
 * Vytvorenie spolocnych helperov pre sablony
 * @param type $class
 * @return type
 */
  protected function createTemplate($class = NULL)
  {
      $servise = $this;
      $template = parent::createTemplate($class);
      $template->addFilter('hlmenuclass', function ($id, $id_registracia, $hl_udaje) {
          $polozka_class = $id_registracia > 2 ? 'adminPol' : '';
          //TODO $classPol .= ' zvyrazni';
          if ($id == $hl_udaje) {
              $polozka_class .= ' active';
          }
开发者ID:petak23,项目名称:echo-msz,代码行数:54,代码来源:BasePresenter.php


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