本文整理汇总了PHP中strings::str_replace方法的典型用法代码示例。如果您正苦于以下问题:PHP strings::str_replace方法的具体用法?PHP strings::str_replace怎么用?PHP strings::str_replace使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类strings
的用法示例。
在下文中一共展示了strings::str_replace方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: parse_params
function parse_params($text, $params)
{
if (!empty($params)) {
foreach ($params as $k => $v) {
if (is_string($v)) {
$k = '%' . $k . '%';
$text = strings::str_replace($k, $v, $text);
}
}
}
$text = preg_replace('@\\%.*\\%@U', '', $text);
return $text;
}
示例2: _parse
function _parse()
{
$text = $this->_body;
if (!is_array($this->_vars)) {
$this->_vars = array();
}
$this->_vars['time'] = date('d.m.Y H:i');
$return = array();
foreach ($this->_vars as $k => $v) {
$return['body'] = strings::str_replace("%{$k}%", $v, $this->_body);
$return['subject'] = strings::str_replace("%{$k}%", $v, $this->_subject);
}
return $return;
}
示例3: translit
/** translit */
public static function translit($s, $allowed_syms = '')
{
$translit = array(' ' => '_', ' ' => '_', 'а' => 'a', 'б' => 'b', 'в' => 'v', 'г' => 'g', 'д' => 'd', 'е' => 'e', 'ё' => 'e', 'ж' => 'j', 'з' => 'z', 'и' => 'i', 'й' => 'y', 'к' => 'k', 'л' => 'l', 'м' => 'm', 'н' => 'n', 'о' => 'o', 'п' => 'p', 'р' => 'r', 'с' => 's', 'т' => 't', 'у' => 'u', 'ф' => 'f', 'х' => 'h', 'ц' => 'ts', 'ч' => 'ch', 'ш' => 'sh', 'щ' => 'sch', 'ъ' => "'", 'ы' => 'i', 'ь' => "'", 'э' => 'е', 'ю' => 'yu', 'я' => 'ya', 'А' => 'A', 'Б' => 'B', 'В' => 'V', 'Г' => 'G', 'Д' => 'D', 'Е' => 'E', 'Ё' => 'E', 'Ж' => 'J', 'З' => 'Z', 'И' => 'I', 'Й' => 'Y', 'К' => 'K', 'Л' => 'L', 'М' => 'M', 'Н' => 'N', 'О' => 'O', 'П' => 'P', 'Р' => 'R', 'С' => 'S', 'Т' => 'T', 'У' => 'U', 'Ф' => 'F', 'Х' => 'H', 'Ц' => 'TS', 'Ч' => 'CH', 'Ш' => 'SH', 'Щ' => 'SCH', 'Ы' => 'I', 'Э' => 'Е', 'Ю' => 'YU', 'Я' => 'YA');
$s = strings::str_replace(array_keys($translit), array_values($translit), $s);
$allowed_syms = preg_quote($allowed_syms);
$preg_exp = sprintf('~[^a-z\\d_%s]~iU', $allowed_syms);
$s = preg_replace($preg_exp, '', $s);
return $s;
}
示例4: collection_filters
/**
* Build filters
*/
protected function collection_filters()
{
/*
'value' =>
array (size=2)
'from' => string '18.04.2014 03:06' (length=16)
'to' => string '18.04.2014 03:06' (length=16)
'operator' => string 'BETWEEN' (length=7)
'connector' => string 'AND' (length=3)
'raw' => null
*/
//
// Filters: Conditions
//
if (!empty($this->filters)) {
foreach ($this->filters as $k => $v) {
$k = $this->_sql_key($k);
$sql = false;
if ($k && array_key_exists($v['connector'], static::$connectors) && array_key_exists($v['operator'], static::$operators)) {
if ($v['raw']) {
// @todo RAW
$sql = strings::str_replace(array(':connector', ':key', ':operator', ':value'), array($v['connector'], $k, $v['operator'], $this->_normalize_value($k, $v['value'])), $v['raw']);
} else {
if (!isset(static::$operators[$v['operator']])) {
throw new collection_filter_exception(__METHOD__ . ' no operator ' . $v['operator']);
}
if (static::$operators[$v['operator']] instanceof Closure) {
$v['key'] = $k;
$sql = call_user_func(static::$operators[$v['operator']], $v);
} else {
if (!empty($v['value'])) {
$sql = $k . ' ' . $v['operator'] . " " . $this->_normalize_value($k, $v['value']);
}
}
}
if ($sql) {
$this->collection->append_where($sql, $v['connector']);
}
}
}
}
//
// Sorting
//
if (!empty($this->orders)) {
$orders = array();
foreach ($this->orders as $k => $v) {
$v = strtoupper($v);
if ('ASC' !== $v && 'DESC' !== $v) {
throw new Collection_Filter_Exception('Bad order: ' . $k);
}
$orders[] = $this->_sql_key($k) . ' ' . $v;
}
$this->collection->set_order(trim(join(', ', $orders)));
}
}