本文整理汇总了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;
}
示例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"'));
}
示例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("&", $line);
$this->assertTrue(substr_count($line, "&") == 2);
}
示例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;
}
示例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;
}
示例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;
}
示例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);
}
}
}
示例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;
}
示例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;
}
示例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');
}
}
示例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') . "&u={$user['userid']}\"><b>{$user['username']}</b></a> \n\t\t\t<a href=\"{$userscript}?" . $vbulletin->session->vars['sessionurl'] . "do=gethost&ip={$user['ipaddress']}\" title=\"" . $vbphrase['resolve_address'] . "\">{$user['ipaddress']}</a> " . construct_link_code($vbphrase['find_posts_by_user'], "../search.php?" . $vbulletin->session->vars['sessionurl'] . "do=finduser&u={$user['userid']}", '_blank') . construct_link_code($vbphrase['view_other_ip_addresses_for_this_user'], "{$userscript}?" . $vbulletin->session->vars['sessionurl'] . "do=doips&u={$user['userid']}&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>';
}
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}