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


PHP substr_count函数代码示例

本文整理汇总了PHP中substr_count函数的典型用法代码示例。如果您正苦于以下问题:PHP substr_count函数的具体用法?PHP substr_count怎么用?PHP substr_count使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


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

示例1: cut

 function cut($str, $limit, $more = " ...")
 {
     if ($str == "" || $str == NULL || is_array($str) || strlen($str) == 0) {
         return $str;
     }
     $str = trim($str);
     if (strlen($str) <= $limit) {
         return $str;
     }
     $str = substr($str, 0, $limit);
     if (!substr_count($str, " ")) {
         if ($more) {
             $str .= " ...";
         }
         return $str;
     }
     while (strlen($str) && $str[strlen($str) - 1] != " ") {
         $str = substr($str, 0, -1);
     }
     $str = substr($str, 0, -1);
     if ($more) {
         $str .= " ...";
     }
     return $str;
 }
开发者ID:JosTrucD,项目名称:phalcon-news,代码行数:25,代码来源:String.php

示例2: testIntrospectionContainsOperationForEachPrototypeOfAPublicMethod

 public function testIntrospectionContainsOperationForEachPrototypeOfAPublicMethod()
 {
     $xml = $this->introspector->introspect('com.zend.framework.IntrospectorTest');
     $this->assertEquals(4, substr_count($xml, 'name="foobar"'));
     $this->assertEquals(1, substr_count($xml, 'name="barbaz"'));
     $this->assertEquals(1, substr_count($xml, 'name="bazbat"'));
 }
开发者ID:netvlies,项目名称:zf,代码行数:7,代码来源:IntrospectorTest.php

示例3: testHtmlSpecialCharsInMessageGetEscapedForValidXml

 /**
  * @group ZF-2062
  * @group ZF-4190
  */
 public function testHtmlSpecialCharsInMessageGetEscapedForValidXml()
 {
     $f = new XmlFormatter();
     $line = $f->format(array('message' => '&key1=value1&key2=value2', 'priority' => 42));
     $this->assertContains("&amp;", $line);
     $this->assertTrue(substr_count($line, "&amp;") == 2);
 }
开发者ID:robertodormepoco,项目名称:zf2,代码行数:11,代码来源:XmlTest.php

示例4: processPassThrough

 public static function processPassThrough($value)
 {
     // This function will parse the pass through data and populate and array with keys and values.
     // Passthrough format is key|value||key|value, etc.
     $passthrough_array = array();
     $cursor_pos = 0;
     $single_bar_pos = 0;
     $double_bar_pos = 0;
     // Find out how many key|value sets there are
     $single_bar_count = substr_count($value, '|');
     // loop passthrough data and add to array
     while ($cursor_pos < strlen($value)) {
         // position of the next single bar (end of key)
         $single_bar_pos = strpos($value, '|', $cursor_pos);
         // position of the next double bar (end of value)
         $double_bar_pos = strpos($value, '||', $cursor_pos);
         // at the end of the string the double bar will be absent and return false.
         // Then set the $double_bar_pos to the entire length of $value
         if ($double_bar_pos == false) {
             $double_bar_pos = strlen($value);
         }
         // set the key
         $array_key = substr($value, $cursor_pos, $single_bar_pos - $cursor_pos);
         // set the value
         $array_value = substr($value, $single_bar_pos + 1, $double_bar_pos - $single_bar_pos - 1);
         // move the cursor to the next key||value
         $cursor_pos = $double_bar_pos + 2;
         // add the key||value to the passthrough array
         $passthrough_array[$array_key] = $array_value;
     }
     // return the final passthrough array
     return $passthrough_array;
 }
开发者ID:jstramel,项目名称:ps_ivr,代码行数:33,代码来源:IfByPhone_Util.php

示例5: neat_r

function neat_r($arr, $return = false)
{
    $out = array();
    $oldtab = "    ";
    $newtab = "  ";
    $lines = explode("\n", print_r($arr, true));
    foreach ($lines as $line) {
        if (substr($line, -5) != "Array") {
            $line = preg_replace("/^(\\s*)\\[[0-9]+\\] => /", "\$1", $line, 1);
        }
        foreach (array("Array" => "", "[" => "", "]" => "", " =>" => ":") as $old => $new) {
            $out = str_replace($old, $new, $out);
        }
        if (in_array(trim($line), array("Array", "(", ")", ""))) {
            continue;
        }
        $indent = "\n";
        $indents = floor((substr_count($line, $oldtab) - 1) / 2);
        if ($indents > 0) {
            for ($i = 0; $i < $indents; $i++) {
                $indent .= $newtab;
            }
        }
        $out[] = $indent . trim($line);
    }
    $out = implode("<br/>", $out) . "\n";
    if ($return == true) {
        return $out;
    }
    echo $out;
}
开发者ID:sreeram77,项目名称:codejam,代码行数:31,代码来源:functions.php

示例6: replace_var_generic

function replace_var_generic($hardware_id, $url_group_server, $id_group = false)
{
    $count_add_ip = substr_count($url_group_server, '$IP$');
    $count_name = substr_count($url_group_server, '$NAME$');
    if ($count_add_ip > 0 or $count_name > 0) {
        $sql = "select IPADDR,NAME,ID from hardware where ID";
        if ($hardware_id != 'ALL') {
            $sql .= " = %s";
            $arg = $hardware_id;
        } else {
            $sql .= " in (select hardware_id from groups_cache where group_id = %s)";
            $arg = $id_group;
        }
        $resdefaultvalues = mysql2_query_secure($sql, $_SESSION['OCS']["readServer"], $arg);
        while ($item = mysql_fetch_object($resdefaultvalues)) {
            $url_temp = str_replace('$IP$', $item->IPADDR, $url_group_server);
            $url[$item->ID] = str_replace('$NAME$', $item->NAME, $url_temp);
        }
    } elseif ($hardware_id != 'ALL') {
        $url[$hardware_id] = $url_group_server;
    } else {
        $sql = "select ID from hardware where ID";
        $sql .= " in (select hardware_id from groups_cache where group_id = %s)";
        $arg = $id_group;
        $resdefaultvalues = mysql2_query_secure($sql, $_SESSION['OCS']["readServer"], $arg);
        while ($item = mysql_fetch_object($resdefaultvalues)) {
            $url[$item->ID] = $url_group_server;
        }
    }
    return $url;
}
开发者ID:inkoss,项目名称:karoshi-server,代码行数:31,代码来源:function_server.php

示例7: writeBody

 function writeBody($message, $stream, &$length_raw, $boundary = '')
 {
     if ($boundary && !$message->rfc822_header) {
         $s = '--' . $boundary . "\r\n";
         $s .= $this->prepareMIME_Header($message, $boundary);
         $length_raw += strlen($s);
         if ($stream) {
             $this->preWriteToStream($s);
             $this->writeToStream($stream, $s);
         }
     }
     $this->writeBodyPart($message, $stream, $length_raw);
     $boundary_depth = substr_count($message->entity_id, '.');
     if ($boundary_depth) {
         $boundary .= '_part' . $boundary_depth;
     }
     $last = false;
     for ($i = 0, $entCount = count($message->entities); $i < $entCount; $i++) {
         $msg = $this->writeBody($message->entities[$i], $stream, $length_raw, $boundary);
         if ($i == $entCount - 1) {
             $last = true;
         }
     }
     if ($boundary && $last) {
         $s = "--" . $boundary . "--\r\n\r\n";
         $length_raw += strlen($s);
         if ($stream) {
             $this->preWriteToStream($s);
             $this->writeToStream($stream, $s);
         }
     }
 }
开发者ID:innomatic-libs,项目名称:squirrelmaillib,代码行数:32,代码来源:Deliver.class.php

示例8: ParseHeaderFooter

 private function ParseHeaderFooter($str, $uid = null)
 {
     $str = preg_replace_callback('/%sort_?link:([a-z0-9_]+)%/i', array(__CLASS__, 'GenSortlink'), $str);
     if (strpos($str, '%search_form%') !== false) {
         wpfb_loadclass('Output');
         $str = str_replace('%search_form%', WPFB_Output::GetSearchForm("", $_GET), $str);
     }
     $str = preg_replace_callback('/%print_?(script|style):([a-z0-9_-]+)%/i', array(__CLASS__, 'PrintScriptCallback'), $str);
     if (empty($uid)) {
         $uid = uniqid();
     }
     $str = str_replace('%uid%', $uid, $str);
     $count = 0;
     $str = preg_replace("/jQuery\\((.+?)\\)\\.dataTable\\s*\\((.*?)\\)(\\.?.*?)\\s*;/", 'jQuery($1).dataTable((function(options){/*%WPFB_DATA_TABLE_OPTIONS_FILTER%*/})($2))$3;', $str, -1, $count);
     if ($count > 0) {
         $dataTableOptions = array();
         list($sort_field, $sort_dir) = wpfb_call('Output', 'ParseSorting', $this->current_list->file_order);
         $file_tpl = WPFB_Core::GetTpls('file', $this->file_tpl_tag);
         if (($p = strpos($file_tpl, "%{$sort_field}%")) > 0) {
             // get the column index of field to sort
             $col_index = substr_count($file_tpl, "</t", 0, $p);
             $dataTableOptions["aaSorting"] = array(array($col_index, strtolower($sort_dir)));
         }
         if ($this->current_list->page_limit > 0) {
             $dataTableOptions["iDisplayLength"] = $this->current_list->page_limit;
         }
         $str = str_replace('/*%WPFB_DATA_TABLE_OPTIONS_FILTER%*/', " var wpfbOptions = " . json_encode($dataTableOptions) . "; " . " if('object' == typeof(options)) { for (var v in options) { wpfbOptions[v] = options[v]; } }" . " return wpfbOptions; ", $str);
     }
     return $str;
 }
开发者ID:parsonsc,项目名称:dofe,代码行数:30,代码来源:ListTpl.php

示例9: isIpv4

 /**
  * Checks if the ip is v4.
  *
  * @param string $ip IP to check
  *
  * @return bool return true if ipv4
  */
 public static function isIpv4($requestIp)
 {
     if (substr_count($requestIp, ':') > 1) {
         return false;
     }
     return true;
 }
开发者ID:cloudflare,项目名称:cf-ip-rewrite,代码行数:14,代码来源:IpUtils.php

示例10: addAdminScript

 public static function addAdminScript()
 {
     $checkJqueryLoaded = false;
     $document = JFactory::getDocument();
     $header = $document->getHeadData();
     JHTML::_('behavior.framework');
     if (!version_compare(JVERSION, '3.0', 'ge')) {
         foreach ($header['scripts'] as $scriptName => $scriptData) {
             if (substr_count($scriptName, '/jquery')) {
                 $checkJqueryLoaded = true;
             }
         }
         //Add js
         if (!$checkJqueryLoaded) {
             $document->addScript(JURI::root() . 'components/com_bt_socialconnect/assets/js/jquery.min.js');
         }
     }
     $document->addScript(JURI::root() . 'components/com_bt_socialconnect/assets/js/default.js');
     $document->addScript(JURI::root() . 'components/com_bt_socialconnect/assets/js/menu.js');
     $document->addScript(JURI::root() . 'administrator/components/com_bt_socialconnect/assets/js/bt_social.js');
     $document->addScriptDeclaration('jQuery.noConflict();');
     $document->addStyleSheet(JURI::root() . 'components/com_bt_socialconnect/assets/icon/admin.css');
     $document->addStyleSheet(JURI::root() . 'components/com_bt_socialconnect/assets/css/legacy.css');
     $document->addStyleSheet(JURI::root() . 'administrator/components/com_bt_socialconnect/assets/css/bt_social.css');
     if (!Bt_SocialconnectLegacyHelper::isLegacy()) {
         JHtml::_('formbehavior.chosen', 'select');
     }
 }
开发者ID:juanferden,项目名称:adoperp,代码行数:28,代码来源:helper.php

示例11: construct_ip_register_table

function construct_ip_register_table($ipaddress, $prevuserid, $depth = 1)
{
    global $vbulletin, $vbphrase;
    $depth--;
    if (VB_AREA == 'AdminCP') {
        $userscript = 'usertools.php';
    } else {
        $userscript = 'user.php';
    }
    if (substr($ipaddress, -1) == '.' or substr_count($ipaddress, '.') < 3) {
        // ends in a dot OR less than 3 dots in IP -> partial search
        $ipaddress_match = "ipaddress LIKE '" . $vbulletin->db->escape_string_like($ipaddress) . "%'";
    } else {
        // exact match
        $ipaddress_match = "ipaddress = '" . $vbulletin->db->escape_string($ipaddress) . "'";
    }
    $users = $vbulletin->db->query_read_slave("\n\t\tSELECT  userid, username, ipaddress\n\t\tFROM " . TABLE_PREFIX . "user AS user\n\t\tWHERE {$ipaddress_match} AND\n\t\t\tipaddress <> '' AND\n\t\t\tuserid <> {$prevuserid}\n\t\tORDER BY username\n\t");
    $retdata = '';
    while ($user = $vbulletin->db->fetch_array($users)) {
        $retdata .= '<li>' . "<a href=\"user.php?" . $vbulletin->session->vars['sessionurl'] . "do=" . iif(VB_AREA == 'ModCP', 'viewuser', 'edit') . "&amp;u={$user['userid']}\"><b>{$user['username']}</b></a> &nbsp;\n\t\t\t<a href=\"{$userscript}?" . $vbulletin->session->vars['sessionurl'] . "do=gethost&amp;ip={$user['ipaddress']}\" title=\"" . $vbphrase['resolve_address'] . "\">{$user['ipaddress']}</a> &nbsp; " . construct_link_code($vbphrase['find_posts_by_user'], "../search.php?" . $vbulletin->session->vars['sessionurl'] . "do=finduser&amp;u={$user['userid']}", '_blank') . construct_link_code($vbphrase['view_other_ip_addresses_for_this_user'], "{$userscript}?" . $vbulletin->session->vars['sessionurl'] . "do=doips&amp;u={$user['userid']}&amp;hash=" . CP_SESSIONHASH) . "</li>\n";
        if ($depth > 0) {
            $retdata .= construct_user_ip_table($user['userid'], $user['ipaddress'], $depth);
        }
    }
    if (empty($retdata)) {
        return '';
    } else {
        return '<ul>' . $retdata . '</ul>';
    }
}
开发者ID:holandacz,项目名称:nb4,代码行数:30,代码来源:adminfunctions_user.php

示例12: validation

 function validation($data, $files)
 {
     $errors = parent::validation($data, $files);
     // TODO - this reg expr can be improved
     if (!preg_match("/(\\(*\\s*\\bc\\d{1,2}\\b\\s*\\(*\\)*\\s*(\\(|and|or)\\s*)+\\(*\\s*\\bc\\d{1,2}\\b\\s*\\(*\\)*\\s*\$/i", $data['conditionexpr'])) {
         $errors['conditionexpr'] = get_string('badconditionexpr', 'block_configurable_reports');
     }
     if (substr_count($data['conditionexpr'], '(') != substr_count($data['conditionexpr'], ')')) {
         $errors['conditionexpr'] = get_string('badconditionexpr', 'block_configurable_reports');
     }
     if (isset($this->_customdata['elements']) && is_array($this->_customdata['elements'])) {
         $elements = $this->_customdata['elements'];
         $nel = count($elements);
         if (!empty($elements) && $nel > 1) {
             preg_match_all('/(\\d+)/', $data['conditionexpr'], $matches, PREG_PATTERN_ORDER);
             foreach ($matches[0] as $num) {
                 if ($num > $nel) {
                     $errors['conditionexpr'] = get_string('badconditionexpr', 'block_configurable_reports');
                     break;
                 }
             }
         }
     }
     return $errors;
 }
开发者ID:adonm,项目名称:learning,代码行数:25,代码来源:form.php

示例13: match_variable

 protected function match_variable($src)
 {
     $hash = [];
     while (preg_match("/({(\\\$[\$\\w][^\t]*)})/s", $src, $vars, PREG_OFFSET_CAPTURE)) {
         list($value, $pos) = $vars[1];
         if ($value == '') {
             break;
         }
         if (substr_count($value, '}') > 1) {
             for ($i = 0, $start = 0, $end = 0; $i < strlen($value); $i++) {
                 if ($value[$i] == '{') {
                     $start++;
                 } else {
                     if ($value[$i] == '}') {
                         if ($start == ++$end) {
                             $value = substr($value, 0, $i + 1);
                             break;
                         }
                     }
                 }
             }
         }
         $length = strlen($value);
         $src = substr($src, $pos + $length);
         $hash[sprintf('%03d_%s', $length, $value)] = $value;
     }
     krsort($hash, SORT_STRING);
     return $hash;
 }
开发者ID:tokushima,项目名称:ebi,代码行数:29,代码来源:TemplateVariable.php

示例14: parse_header

	public function parse_header($header) {
		$last_header = '';
		$parsed_header = array();
		for ($j = 0, $end = sizeof($header); $j < $end; $j++) {
			$hd = split(':', $header[$j], 2);
			
			if (preg_match_all("/\s/", $hd[0], $matches) || !isset($hd[1]) || !$hd[1]) {
				if ($last_header) {
					$parsed_header[$last_header] .= "\r\n" . trim($header[$j]);
				}
			} else {
				$last_header = strtolower($hd[0]);
				if (!isset($parsed_header[$last_header])) {
					$parsed_header[$last_header] = '';
				}
				$parsed_header[$last_header] .= (($parsed_header[$last_header]) ? "\r\n" : '') . trim($hd[1]);
			}
		}
		
		foreach ($parsed_header as $hd_name => $hd_content) {
			$start_enc_tag = $stop_enc_tag = 0;
			$pre_text = $enc_text = $post_text = "";
			
			while(1) {
				if (strstr($hd_content, '=?') && strstr($hd_content, '?=') && substr_count($hd_content,'?') > 3) {
					$start_enc_tag = strpos($hd_content, '=?');
					$pre_text = substr($hd_content, 0, $start_enc_tag);
					do {
						$stop_enc_tag = strpos($hd_content, '?=', $stop_enc_tag) + 2;
						$enc_text = substr($hd_content, $start_enc_tag, $stop_enc_tag);
					}
					while (!(substr_count($enc_text, '?') > 3));
					
					$enc_text = explode('?', $enc_text, 5);
					switch (strtoupper($enc_text[2])) {
						case "B":
							$dec_text = base64_decode($enc_text[3]);
							break;
						case "Q":
						default:
							$dec_text = quoted_printable_decode($enc_text[3]);
							$dec_text = str_replace('_', ' ', $dec_text);
							break;
					}
					
					$post_text = substr($hd_content, $stop_enc_tag);
					if (substr(ltrim($post_text), 0, 2) == '=?') {
						$post_text = ltrim($post_text);
					}
					
					$hd_content = $pre_text . $dec_text . $post_text;
					$parsed_header[$hd_name] = $hd_content;
				} else {
					break;
				}
			}
		}
		
		return $parsed_header;
	}
开发者ID:nopticon,项目名称:rockr,代码行数:60,代码来源:mail.php

示例15: link_library_modify_http_response

function link_library_modify_http_response($plugins_response)
{
    foreach ($plugins_response as $response_key => $plugin_response) {
        if (plugin_basename(__FILE__) == $plugin_response->plugin) {
            if (3 <= substr_count($plugin_response->new_version, '.')) {
                $plugin_info = get_plugin_data(__FILE__);
                $period_position = link_library_strposX($plugin_info['Version'], '.', 3);
                if (false !== $period_position) {
                    $current_version = substr($plugin_info['Version'], 0, $period_position);
                } else {
                    $current_version = $plugin_info['Version'];
                }
                $period_position2 = link_library_strposX($plugin_response->new_version, '.', 3);
                if (false !== $period_position) {
                    $new_version = substr($plugin_response->new_version, 0, $period_position2);
                } else {
                    $new_version = $plugin_response->new_version;
                }
                $version_diff = version_compare($current_version, $new_version);
                if (-1 < $version_diff) {
                    unset($plugins_response->{$response_key});
                }
            }
        }
    }
    return $plugins_response;
}
开发者ID:wenhao87,项目名称:WPPlugins,代码行数:27,代码来源:link-library.php


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