本文整理汇总了PHP中MultiByte::str_replace方法的典型用法代码示例。如果您正苦于以下问题:PHP MultiByte::str_replace方法的具体用法?PHP MultiByte::str_replace怎么用?PHP MultiByte::str_replace使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类MultiByte
的用法示例。
在下文中一共展示了MultiByte::str_replace方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: parse
/**
* Turns a comma-separated string or array of terms into an array of Term objects
* @param mixed $terms A comma-separated string or array of string terms
* @param string $term_class The class of the Term object type to create from each string
* @param Vocabulary $vocabulary An instance of the Vocabulary that might hold the terms.
* Use existing term object data if found in the specified vocabulary.
* @return Terms An instance of Terms contianing the specified Term objects
**/
public static function parse( $terms, $term_class = 'Term', $vocabulary = null )
{
if ( is_string( $terms ) ) {
if ( '' === $terms ) {
return new Terms();
}
$terms = trim( MultiByte::str_replace( '"', '"', $terms ) );
// dirrty ;)
$rez = array( '\\"'=>':__unlikely_quote__:', '\\\''=>':__unlikely_apos__:' );
$zer = array( ':__unlikely_quote__:'=>'"', ':__unlikely_apos__:'=>"'" );
// escape
$tagstr = str_replace( array_keys( $rez ), $rez, $terms );
// match-o-matic
preg_match_all( '/((("|((?<= )|^)\')\\S([^\\3]*?)\\3((?=[\\W])|$))|[^,])+/u', $tagstr, $matches );
// cleanup
$terms = array_map( 'trim', $matches[0] );
$terms = preg_replace( array_fill( 0, count( $terms ), '/^(["\'])(((?!").)+)(\\1)$/' ), '$2', $terms );
// unescape
$terms = str_replace( array_keys( $zer ), $zer, $terms );
// hooray
}
if ( is_array( $terms ) ) {
if ( $vocabulary instanceof Vocabulary ) {
foreach ( $terms as $k => $term ) {
if ( $saved_term = $vocabulary->get_term( $term, $term_class ) ) {
$terms[$k] = $saved_term;
}
else {
$terms[$k] = new $term_class( $term );
}
}
//Utils::debug($terms);
}
else {
array_walk( $terms, create_function( '&$tag', '$tag = new ' . $term_class . '($tag);' ) );
}
return new Terms( $terms );
}
return new Terms();
}
示例2: act_display
//.........这里部分代码省略.........
$where_filters['vocabulary'] = array();
if (array_key_exists('tag', $where_filters)) {
$tags = Tags::parse_url_tags($where_filters['tag']);
$not_tag = $tags['exclude_tag'];
$all_tag = $tags['include_tag'];
if (count($not_tag) > 0) {
$where_filters['vocabulary'] = array_merge($where_filters['vocabulary'], array(Tags::vocabulary()->name . ':not:term' => $not_tag));
}
if (count($all_tag) > 0) {
$where_filters['vocabulary'] = array_merge($where_filters['vocabulary'], array(Tags::vocabulary()->name . ':all:term' => $all_tag));
}
$where_filters['tag_slug'] = Utils::slugify($where_filters['tag']);
unset($where_filters['tag']);
}
if (!isset($_GET['preview'])) {
$where_filters['status'] = Post::status('published');
}
if (!isset($posts)) {
$user_filters = Plugins::filter('template_user_filters', $user_filters);
// Work around the tags parameters to Posts::get() being subsumed by the vocabulary parameter
if (isset($user_filters['not:tag'])) {
$user_filters['vocabulary'] = array(Tags::vocabulary()->name . ':not:term' => $user_filters['not:tag']);
unset($user_filters['not:tag']);
}
if (isset($user_filters['tag'])) {
$user_filters['vocabulary'] = array(Tags::vocabulary()->name . ':term_display' => $user_filters['tag']);
unset($user_filters['tag']);
}
$where_filters = $where_filters->merge($user_filters);
$where_filters = Plugins::filter('template_where_filters', $where_filters);
$posts = Posts::get($where_filters);
}
$this->assign('posts', $posts);
if ($posts !== false && count($posts) > 0) {
if (count($posts) == 1) {
$post = $posts instanceof Post ? $posts : reset($posts);
Stack::add('body_class', Post::type_name($post->content_type) . '-' . $post->id);
Stack::add('body_class', 'single');
} else {
$post = reset($posts);
Stack::add('body_class', 'multiple');
}
$this->assign('post', $post);
$type = Post::type_name($post->content_type);
} elseif ($posts === false || isset($where_filters['page']) && $where_filters['page'] > 1 && count($posts) == 0) {
if ($this->template_exists('404')) {
$fallback = array('404');
// Replace template variables with the 404 rewrite rule
$this->request->{URL::get_matched_rule()->name} = false;
$this->request->{URL::set_404()->name} = true;
$this->matched_rule = URL::get_matched_rule();
// 404 status header sent in act_display_404, but we're past
// that, so send it now.
header('HTTP/1.1 404 Not Found', true, 404);
} else {
$this->display('header');
echo '<h2>';
_e("Whoops! 404. The page you were trying to access is not really there. Please try again.");
echo '</h2>';
header('HTTP/1.1 404 Not Found', true, 404);
$this->display('footer');
die;
}
}
$extract = $where_filters->filter_keys('page', 'type', 'id', 'slug', 'posttag', 'year', 'month', 'day', 'tag', 'tag_slug');
foreach ($extract as $key => $value) {
${$key} = $value;
}
$this->assign('page', isset($page) ? $page : 1);
if (!isset($fallback)) {
// Default fallbacks based on the number of posts
$fallback = array('{$type}.{$id}', '{$type}.{$slug}', '{$type}.tag.{$posttag}');
if (count($posts) > 1) {
$fallback[] = '{$type}.multiple';
$fallback[] = 'multiple';
} else {
$fallback[] = '{$type}.single';
$fallback[] = 'single';
}
}
$searches = array('{$id}', '{$slug}', '{$year}', '{$month}', '{$day}', '{$type}', '{$tag}');
$replacements = array(isset($post) && $post instanceof Post ? $post->id : '-', isset($post) && $post instanceof Post ? $post->slug : '-', isset($year) ? $year : '-', isset($month) ? $month : '-', isset($day) ? $day : '-', isset($type) ? $type : '-', isset($tag_slug) ? $tag_slug : '-');
$fallback[] = 'home';
$fallback = Plugins::filter('template_fallback', $fallback, $posts, isset($post) ? $post : null);
$fallback = array_values(array_unique(MultiByte::str_replace($searches, $replacements, $fallback)));
for ($z = 0; $z < count($fallback); $z++) {
if (MultiByte::strpos($fallback[$z], '{$posttag}') !== false && isset($post) && $post instanceof Post) {
$replacements = array();
if ($alltags = $post->tags) {
foreach ($alltags as $current_tag) {
$replacements[] = MultiByte::str_replace('{$posttag}', $current_tag->term, $fallback[$z]);
}
array_splice($fallback, $z, 1, $replacements);
} else {
break;
}
}
}
return $this->display_fallback($fallback);
}
示例3: generate_title
private function generate_title($min = 2, $max = 8)
{
// get a fake paragraph of text that's 1 line long
$text = $this->generate_paragraph(1, 1);
$text = MultiByte::strtolower($text);
// remove commas and periods
$text = MultiByte::str_replace(array('.', ','), '', $text);
$words = explode(' ', $text);
// randomize the words list
shuffle($words);
// we can only get the max number of words the paragraph generated
if ($min > count($words)) {
$min = count($words);
}
if ($max > count($words)) {
$max = count($words);
}
// decide how many words we want
$how_many_words = mt_rand($min, $max);
$title = array();
for ($i = 0; $i < $how_many_words; $i++) {
// snag a random word
$title[] = array_pop($words);
}
$title = implode(' ', $title);
// capitalize the first letter of each word
$title = MultiByte::ucwords($title);
return $title;
}