本文整理匯總了PHP中string::rereplace方法的典型用法代碼示例。如果您正苦於以下問題:PHP string::rereplace方法的具體用法?PHP string::rereplace怎麽用?PHP string::rereplace使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類string
的用法示例。
在下文中一共展示了string::rereplace方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: parse
/**
* @brief Parse the human data and return html
*
* @param string $data The data to parse
* @return string The parsed data
*/
public function parse($content)
{
$str = $content;
$str = string::rereplace($str, '/</', '<');
$str = string::rereplace($str, '/>/', '>');
$str = string::rereplace($str, '/\\\\"/', '"');
// First chunk everything into paragraphs...
$str = string::rereplace($str, '/(.+)/', '<p>\\1</p>');
// Then take care of multiple newlines
$str = string::rereplace($str, '/(\\r|\\n){2}/', '<br>');
// The usual, bold, italics, etc...
$str = string::rereplace($str, '/\\/(.*?)\\//', '<em>\\1</em>');
$str = string::rereplace($str, '/\\*(.*?)\\*/', '<strong>\\1</strong>');
$str = string::rereplace($str, '/_(.*?)_/', '<u>\\1</u>');
$tag_re = '/\\#([a-zA-Z0-9]+)/s';
$group_re = '/\\!([a-zA-Z0-9]+)/s';
/*
preg_match_all($tag_re, $content, $tags);
preg_match_all($group_re, $content, $groups);
$this->setMeta(MarkupParser::META_TAGS, $tags[1]);
$this->setMeta(MarkupParser::META_GROUPS, $groups[1]);
*/
$str = string::rereplace($str, $tag_re, '<a href="/tags/\\1">#\\1</a>');
$str = string::rereplace($str, $group_re, '<a href="/groups/\\1">!\\1</a>');
$str = string::rereplace($str, '/\\@([a-zA-Z0-9]+)/s', '<a href="/user/\\1">@\\1</a>');
// A bit of a hack...but it works... let me know if you have a regex that fixes this :p
$str = string::rereplace($str, '/<strong><\\/strong>/', '**');
$str = string::rereplace($str, '/<em><\\/em>/', '//');
$str = string::rereplace($str, '/<u><\\/u>/', '__');
$str = string::rereplace($str, '/(https?:\\/\\/\\S+)/', '<a href="\\1" rel="nofollow">\\1</a>');
return $str;
}