本文整理汇总了PHP中mb_substr_count函数的典型用法代码示例。如果您正苦于以下问题:PHP mb_substr_count函数的具体用法?PHP mb_substr_count怎么用?PHP mb_substr_count使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了mb_substr_count函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: cutString
public static function cutString($str, $len, $more)
{
if ($str == "" || $str == NULL) {
return $str;
}
if (is_array($str)) {
return $str;
}
$str = strip_tags($str, '');
$str = trim($str);
if (mb_strlen($str) <= $len) {
return $str;
}
$str = mb_substr($str, 0, $len);
if ($str != "") {
if (!mb_substr_count($str, " ")) {
if ($more) {
$str .= " ...";
}
return $str;
}
while (mb_strlen($str) && $str[mb_strlen($str) - 1] != " ") {
$str = mb_substr($str, 0, -1);
}
$str = mb_substr($str, 0, -1);
if ($more) {
$str .= " ...";
}
}
return $str;
}
示例2: cut
function cut($text, $lenght = 250)
{
$text = html_entity_decode($text);
$text = preg_replace("/" . self::$fakeSymb . "/", "", $text);
//move all tags to array tags
$text = preg_replace("/(<\\/?)(\\w+)([^>]*>)/e", "html_cutter::tagOut('\\0')", $text);
//check how many tags in cutter text to fix cut length
$preCut = mb_substr($text, 0, $lenght);
$fakeCount = mb_substr_count($preCut, self::$fakeSymb);
//cut string
$text = mb_substr($text, 0, $lenght + $fakeCount * mb_strlen(self::$fakeSymb));
//remove last word
$text = preg_replace("/\\S*\$/", "", $text);
//return tags back
self::$tagCounter = 0;
$text = preg_replace("/" . self::$fakeSymb . "/e", "html_cutter::tagIn()", $text);
//get count not closed tags
$closeCount = count(self::$openTags) - count(self::$closeTags);
//close opened tags
for ($i = 0; $i < $closeCount; $i++) {
$tagName = array_pop(self::$openTags);
$text .= "</{$tagName}>";
}
return $text;
}
示例3: testCodeWithEmbedOnPsc
public function testCodeWithEmbedOnPsc()
{
$this->assertContains("requireLoad(", $code = (string) $this->createSnippet('no code', array())->loadOnPscReady(TRUE)->html());
$this->assertContains('<script type="text/javascript"', $code);
// nicht 2 script tags
$this->assertEquals(1, mb_substr_count($code, '</script>'));
}
示例4: apply
public function apply($value)
{
if (mb_check_encoding($value, 'UTF-16') && mb_substr_count($value, "") > 0) {
$value = mb_convert_encoding($value, 'UTF-8', 'UTF-16');
}
return $value;
}
示例5: configureByConfigString
/**
* Configure the feature with a single string
*
* Format of config string should be: "100|1,2,3,4|ROLE_ADMIN,ROLE_PREMIUM|caretaker,supporter,staff"
* - where "100" is the percentage of user for that the feature should be enabled.
* - where "1,2,3,4" are a comma-separated list of user IDs that should have this feature.
* - where "ROLE_ADMIN,ROLE_PREMIUM" are a comma-separated list of the role names that should have this feature.
* - where "caretaker,supporter,staff" are a comma-separated list of the role names that should have this feature.
*
* Empty section are allowed and silently ignored as long as the format of the string stays the same:
* e.g. "20||ROLE_PREMIUM|" is valid (20 percent and additionally al users with ROLE_PREMIUM will get the feature)
* e.g. "|||" is valid and will completely disable this feature, but it is recommend to use "0|||" instead.
*
* @param string $configString
* @return bool Successfully parsed the config string or not
*/
public function configureByConfigString($configString)
{
$successsfullyConfigured = false;
if (true === is_string($configString) && '' !== $configString && 3 === mb_substr_count($configString, self::FEATURE_CONFIGSTRING_SECTION_DELIMITER)) {
list($percentageString, $usersString, $rolesString, $groupsString) = explode(self::FEATURE_CONFIGSTRING_SECTION_DELIMITER, $configString);
$this->setPercentage((int) 0);
if (true === is_numeric($percentageString)) {
$this->setPercentage((int) $percentageString);
}
$this->setUsers(array());
if (true === is_string($usersString) && '' !== $usersString) {
$userIds = explode(self::FEATURE_CONFIGSTRING_ENTRY_DELIMITER, $usersString);
$this->setUsers($userIds);
}
$this->setRoles(array());
if (true === is_string($rolesString) && '' !== $rolesString) {
$roleNames = explode(self::FEATURE_CONFIGSTRING_ENTRY_DELIMITER, $rolesString);
$this->setRoles($roleNames);
}
$this->setGroups(array());
if (true === is_string($groupsString) && '' !== $groupsString) {
$groupNames = explode(self::FEATURE_CONFIGSTRING_ENTRY_DELIMITER, $groupsString);
$this->setGroups($groupNames);
}
$successsfullyConfigured = true;
}
return $successsfullyConfigured;
}
示例6: display_compile_output
function display_compile_output($output, $success)
{
$color = "#6666FF";
$msg = "not finished yet";
if ($output !== NULL) {
if ($success) {
$color = '#1daa1d';
$msg = 'successful';
if (!empty($output)) {
$msg .= ' (with ' . mb_substr_count($output, "\n") . ' line(s) of output)';
}
} else {
$color = 'red';
$msg = 'unsuccessful';
}
}
echo '<h3 id="compile">' . (empty($output) ? '' : "<a class=\"collapse\" href=\"javascript:collapse('compile')\">") . "Compilation <span style=\"color:{$color};\">{$msg}</span>" . (empty($output) ? '' : "</a>") . "</h3>\n\n";
if (!empty($output)) {
echo '<pre class="output_text" id="detailcompile">' . specialchars($output) . "</pre>\n\n";
} else {
echo '<p class="nodata" id="detailcompile">' . "There were no compiler errors or warnings.</p>\n";
}
// Collapse compile output when compiled succesfully.
if ($success) {
echo "<script type=\"text/javascript\">\n<!--\n\tcollapse('compile');\n// -->\n</script>\n";
}
}
示例7: execute
public function execute()
{
if ($this->isCaseInsensitive()) {
return mb_substr_count(mb_strtolower($this->getValue()), mb_strtolower($this->needle));
} else {
return mb_substr_count($this->getValue(), $this->needle);
}
}
示例8: figure_count
function figure_count($texts)
{
global $figure;
$figcnt = 0;
foreach ($texts as $text_line) {
$figcnt += mb_substr_count($text_line, $figure);
}
return $figcnt;
}
示例9: getParsedTag
/**
* @see \wcf\system\bbcode\IBBCode::getParsedTag()
*/
public function getParsedTag(array $openingTag, $content, array $closingTag, BBCodeParser $parser)
{
// copyright
TeraliosBBCodesCopyright::callCopyright();
$content = StringUtil::trim($content);
if (!empty($content) || mb_strpos($content, '[.]') !== false && mb_strpos($content, '[:]') !== false) {
$content = str_replace('[.]', '[*]', $content);
// build main list elements
$listElements = preg_split('#\\[\\*\\]#', $content, -1, PREG_SPLIT_NO_EMPTY);
foreach ($listElements as $key => $val) {
$val = StringUtil::trim($val);
if (empty($val) || $val == '<br />') {
unset($listElements[$key]);
} else {
$listElements[$key] = $val;
}
}
// build list
if (!empty($listElements)) {
$listContent = '';
foreach ($listElements as $point) {
if (mb_substr_count($point, '[:]') == 1) {
// reset key and value.
$key = $value = '';
// split list element on [:] in key and definition of key.
list($key, $value) = preg_split('#\\[:\\]#', $point, -1);
$key = StringUtil::trim($key);
$value = StringUtil::trim($value);
if (empty($value)) {
$value = WCF::getLanguage()->get('wcf.bbcode.dlist.noDefinition');
}
// key is not empty.
if (!empty($key)) {
if ($parser->getOutputType() == 'text/html') {
$listContent .= '<dt>' . $key . '</dt><dd>' . $value . '</dd>';
} else {
if ($parser->getOutputType() == 'text/simplified-html') {
$listContent .= '*' . $key . ': ' . $value . "\n";
}
}
}
}
}
if (!empty($listContent)) {
if ($parser->getOutputType() == 'text/html') {
return '<dl class="dlistBBCode">' . $listContent . '</dl><span></span>';
} else {
if ($parser->getOutputType() == 'text/simplified-html') {
return $listContent;
}
}
}
}
}
return '[dlist]' . $content . '[/dlist]';
}
示例10: _check_language
function _check_language()
{
$serverName = $this->request->serverName;
//语言与当前浏览器设置有关
$lan = $this->request->preferredLanguage;
if (mb_substr_count($serverName, '.') == 2) {
$lan = substr($serverName, 0, strpos($serverName, '.'));
}
Yii::app()->language = $lan;
}
示例11: __construct
public function __construct($tldCheck = true)
{
$this->checks[] = new NoWhitespace();
$this->checks[] = new Contains('.');
$this->checks[] = new Length(3, null);
$this->tldCheck($tldCheck);
$this->otherParts = new AllOf(new Alnum('-'), new Not(new StartsWith('-')), new OneOf(new Not(new Contains('--')), new AllOf(new StartsWith('xn--'), new Callback(function ($str) {
return mb_substr_count($str, '--') == 1;
}))));
}
示例12: testShorting
public function testShorting()
{
$searchWord = 'für';
$h = new Kwf_View_Helper_HighlightTerms();
$res = $h->highlightTerms($searchWord, $this->_text, array('maxReturnLength' => 200, 'maxReturnBlocks' => 4));
$highlights = mb_substr_count($res, '<span ');
$this->assertEquals(4, $highlights);
$highlights = mb_substr_count($res, ' ... ');
$this->assertEquals(3, $highlights);
$this->assertLessThanOrEqual(200, mb_strlen(strip_tags($res)));
}
示例13: _queryToArray
/**
* @param $query_string String
* @return Array
*/
private function _queryToArray($query_string)
{
$result = [];
if (mb_substr_count($query_string, '=')) {
foreach (explode('&', $query_string) as $couple) {
list($key, $val) = explode('=', $couple);
$result[$key] = $val;
}
}
return empty($result) ? false : $result;
}
示例14: frutCounter
function frutCounter($string)
{
$string = str_replace(PHP_EOL, " ", $string);
$arr = array_unique(array_filter(explode(" ", $string)));
$frutArrSorted = array();
foreach ($arr as $v) {
$v = trim($v);
$frutArrSorted[$v] = mb_substr_count($string, $v);
}
array_multisort($frutArrSorted, SORT_DESC);
return $frutArrSorted;
}
示例15: parseAmountDecimalSeparator
/**
* Parses an amount's decimal separator.
*
* @param string $amount
* Any optionally localized numeric value.
*
* @return string|false
* The amount with its decimal separator replaced by a period, or FALSE in
* case of failure.
*/
protected function parseAmountDecimalSeparator($amount)
{
$decimal_separator_counts = [];
foreach ($this->decimalSeparators as $decimal_separator) {
$decimal_separator_counts[$decimal_separator] = \mb_substr_count($amount, $decimal_separator);
}
$decimal_separator_counts_filtered = array_filter($decimal_separator_counts);
if (count($decimal_separator_counts_filtered) > 1 || reset($decimal_separator_counts_filtered) !== FALSE && reset($decimal_separator_counts_filtered) != 1) {
return FALSE;
}
return str_replace($this->decimalSeparators, '.', $amount);
}