• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

PHP utf8_substr_replace函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: autoTag

 /**
  * Inserts tag links into an HTML-formatted text.
  *
  * @param string $html
  * @param array $tags
  * @param array $options
  * @return string
  */
 public static function autoTag($html, array $tags, array &$options = array())
 {
     if (empty($tags)) {
         return $html;
     }
     $html = strval($html);
     $htmlNullified = utf8_strtolower($html);
     $htmlNullified = preg_replace_callback('#<a[^>]+>.+?</a>#', array(__CLASS__, '_autoTag_nullifyHtmlCallback'), $htmlNullified);
     $htmlNullified = preg_replace_callback('#<[^>]+>#', array(__CLASS__, '_autoTag_nullifyHtmlCallback'), $htmlNullified);
     // prepare the options
     $onceOnly = empty($options['onceOnly']) ? false : true;
     $options['autoTagged'] = array();
     // reset this
     // sort tags with the longest one first
     // since 1.0.3
     usort($tags, array(__CLASS__, '_autoTag_sortTagsByLength'));
     foreach ($tags as $tag) {
         $offset = 0;
         $tagText = utf8_strtolower($tag['tag']);
         $tagLength = utf8_strlen($tagText);
         while (true) {
             $pos = utf8_strpos($htmlNullified, $tagText, $offset);
             if ($pos !== false) {
                 // the tag has been found
                 if (self::_autoTag_hasValidCharacterAround($html, $pos, $tagText)) {
                     // and it has good surrounding characters
                     // start replacing
                     $displayText = utf8_substr($html, $pos, $tagLength);
                     $template = new XenForo_Template_Public('tinhte_xentag_bb_code_tag_tag');
                     $template->setParam('tag', $tag);
                     $template->setParam('displayText', $displayText);
                     $replacement = $template->render();
                     if (strlen($replacement) === 0) {
                         // in case template system hasn't been initialized
                         $replacement = sprintf('<a href="%s">%s</a>', XenForo_Link::buildPublicLink('tags', $tag), $displayText);
                     }
                     $html = utf8_substr_replace($html, $replacement, $pos, $tagLength);
                     $htmlNullified = utf8_substr_replace($htmlNullified, str_repeat('_', utf8_strlen($replacement)), $pos, $tagLength);
                     // sondh@2012-09-20
                     // keep track of the auto tagged tags
                     $options['autoTagged'][$tagText][$pos] = $replacement;
                     $offset = $pos + utf8_strlen($replacement);
                     if ($onceOnly) {
                         // auto link only once per tag
                         // break the loop now
                         break;
                         // while (true)
                     }
                 } else {
                     $offset = $pos + $tagLength;
                 }
             } else {
                 // no match has been found, stop working with this tag
                 break;
                 // while (true)
             }
         }
     }
     return $html;
 }
开发者ID:maitandat1507,项目名称:Tinhte_XenTag,代码行数:68,代码来源:Integration.php


示例2: utf8_ucwords_callback

/**
* Callback function for preg_replace_callback call in utf8_ucwords
* You don't need to call this yourself
* @param array of matches corresponding to a single word
* @return string with first char of the word in uppercase
* @see utf8_ucwords
* @see utf8_strtoupper
* @package utf8
* @subpackage strings
*/
function utf8_ucwords_callback($matches)
{
    $leadingws = $matches[2];
    $ucfirst = utf8_strtoupper($matches[3]);
    $ucword = utf8_substr_replace(ltrim($matches[0]), $ucfirst, 0, 1);
    return $leadingws . $ucword;
}
开发者ID:HawesDomingue,项目名称:mechanic-watson,代码行数:17,代码来源:ucwords.php


示例3: update

 public static function update($targetClass, $targetPath, $sourceClass, $sourcesContents)
 {
     $targetContents = str_replace($sourceClass, $targetClass, $sourcesContents);
     $php = '<?php';
     $pos = utf8_strpos($targetContents, $php);
     if ($pos !== false) {
         $replacement = sprintf("%s\n\n// updated by %s at %s", $php, __CLASS__, date('c'));
         $targetContents = utf8_substr_replace($targetContents, $replacement, $pos, utf8_strlen($php));
     }
     $classPrefix = substr($targetClass, 0, strpos($targetClass, 'ShippableHelper_'));
     $offset = 0;
     while (true) {
         if (!preg_match('#DevHelper_Helper_ShippableHelper_[a-zA-Z_]+#', $targetContents, $matches, PREG_OFFSET_CAPTURE, $offset)) {
             break;
         }
         $siblingSourceClass = $matches[0][0];
         $offset = $matches[0][1];
         $siblingTargetClass = str_replace('DevHelper_Helper_', $classPrefix, $siblingSourceClass);
         $targetContents = substr_replace($targetContents, $siblingTargetClass, $offset, strlen($siblingSourceClass));
         class_exists($siblingTargetClass);
         $offset += 1;
     }
     $targetContents = preg_replace('#\\* @version \\d+\\s*\\n#', '$0 * @see ' . $sourceClass . "\n", $targetContents, -1, $count);
     return DevHelper_Generator_File::filePutContents($targetPath, $targetContents);
 }
开发者ID:maitandat1507,项目名称:DevHelper,代码行数:25,代码来源:ShippableHelper.php


示例4: truncate

function truncate($text, $length = 30, $truncateString = '...')
{
    if (utf8_strlen($text) > $length) {
        return utf8_substr_replace($text, $truncateString, $length - utf8_strlen($truncateString));
    } else {
        return $text;
    }
}
开发者ID:BackupTheBerlios,项目名称:stato-svn,代码行数:8,代码来源:text_helper.php


示例5: renderTagUrl

 public function renderTagUrl(array $tag, array $rendererStates)
 {
     if (!empty($tag['option'])) {
         $url = $tag['option'];
         $text = $this->renderSubTree($tag['children'], $rendererStates);
     } else {
         $url = $this->stringifyTree($tag['children']);
         $text = urldecode($url);
         if (!preg_match('/./u', $text)) {
             $text = $url;
         }
         $text = XenForo_Helper_String::censorString($text);
         if (!empty($rendererStates['shortenUrl'])) {
             $length = utf8_strlen($text);
             if ($length > 100) {
                 $text = utf8_substr_replace($text, '...', 35, $length - 35 - 45);
             }
         }
         $text = htmlspecialchars($text);
     }
     $url = $this->_getValidUrl($url);
     if (!$url) {
         return $text;
     } else {
         list($class, $target, $type) = XenForo_Helper_String::getLinkClassTarget($url);
         $class = $class ? " class=\"{$class}\"" : '';
         $target = $target ? " target=\"{$target}\"" : '';
         if ($type == 'internal') {
             $noFollow = '';
         } else {
             $noFollow = empty($rendererStates['noFollowDefault']) ? '' : ' rel="nofollow"';
         }
         $url = XenForo_Helper_String::censorString($url);
         $test = $this->isImage($url);
         if ($test) {
             return sprintf($this->_imageTemplate, htmlspecialchars($url), $rendererStates['lightBox'] ? ' LbImage' : '');
         }
         return $this->_wrapInHtml('<a href="' . htmlspecialchars($url) . '"' . $target . $class . $noFollow . '>', '</a>', $text);
     }
 }
开发者ID:Sywooch,项目名称:forums,代码行数:40,代码来源:BBcode.php


示例6: renderTagUrl

 /**
  * Renders a URL tag.
  *
  * @param array $tag Information about the tag reference; keys: tag, option, children
  * @param array $rendererStates Renderer states to push down
  *
  * @return string Rendered tag
  */
 public function renderTagUrl(array $tag, array $rendererStates)
 {
     if (!empty($tag['option'])) {
         $url = $tag['option'];
         $text = $this->renderSubTree($tag['children'], $rendererStates);
     } else {
         $url = $this->stringifyTree($tag['children']);
         $text = rawurldecode($url);
         if (!preg_match('/./u', $text)) {
             $text = $url;
         }
         $text = XenForo_Helper_String::censorString($text);
         if (!empty($rendererStates['shortenUrl'])) {
             $length = utf8_strlen($text);
             if ($length > 100) {
                 $text = utf8_substr_replace($text, '...', 35, $length - 35 - 45);
             }
         }
         $text = htmlspecialchars($text);
     }
     $url = $this->_getValidUrl($url);
     if (!$url) {
         return $text;
     } else {
         list($class, $target, $type) = XenForo_Helper_String::getLinkClassTarget($url);
         if ($type == 'internal') {
             $noFollow = '';
         } else {
             $noFollow = empty($rendererStates['noFollowDefault']) ? '' : ' rel="nofollow"';
         }
         $href = XenForo_Helper_String::censorString($url);
         if ($rendererStates['disableProxying']) {
             $proxyHref = false;
         } else {
             $proxyHref = $this->_handleLinkProxyOption($href, $type);
         }
         $proxyAttr = '';
         if ($proxyHref) {
             $proxyAttr = ' data-proxy-href="' . htmlspecialchars($proxyHref) . '"';
             $class .= ' ProxyLink';
         }
         $class = $class ? " class=\"{$class}\"" : '';
         $target = $target ? " target=\"{$target}\"" : '';
         return $this->_wrapInHtml('<a href="' . htmlspecialchars($href) . '"' . $target . $class . $proxyAttr . $noFollow . '>', '</a>', $text);
     }
 }
开发者ID:darkearl,项目名称:projectT122015,代码行数:54,代码来源:Base.php


示例7: spell_check

/**
 * Spellchecker. Called by an AJAX request
 *
 * Runs the given Text through Aspell and prints XHTML with
 * markup. The first char represents the error code:
 *
 * 0 - No spelling mistakes
 * 1 - Spelling mistakes found
 * 2 - An error occurred error message follows
 *
 * @author Andreas Gohr <[email protected]>
 */
function spell_check()
{
    global $spell;
    $string = $_POST['data'];
    $misspell = false;
    // for streamlined line endings
    $string = preg_replace("/(\r\n)|(\r)/", "\n", $string);
    $string = htmlspecialchars($string);
    // make sure multiple spaces and leading are kept
    $string = preg_replace('/^ /m', '&nbsp;', $string);
    $string = preg_replace('/  /', '&nbsp; ', $string);
    // we need the text as array later
    $data = explode("\n", $string);
    // don't check links and medialinks for spelling errors
    $string = preg_replace_callback('/\\{\\{(.*?)(\\|(.*?))?(\\}\\})/', 'spaceslink', $string);
    $string = preg_replace_callback('/\\[\\[(.*?)(\\|(.*?))?(\\]\\])/', 'spaceslink', $string);
    // run aspell in terse sgml mode, ignore nbsp as correct word
    if (!$spell->runAspell($string, $out, $err, array('!', '+html', '@nbsp'))) {
        print '2';
        //to indicate an error
        print "An error occurred while trying to run the spellchecker:\n";
        print $err;
        return;
    }
    #use this to debug raw aspell output
    #print "1$out"; return;
    // go through the result
    $lines = split("\n", $out);
    $rcnt = count($lines) - 1;
    // aspell result count
    $lcnt = count($data) + 1;
    // original line counter
    for ($i = $rcnt; $i >= 0; $i--) {
        $line = trim($lines[$i]);
        if ($line[0] == '@') {
            continue;
        }
        // comment
        if ($line[0] == '*') {
            continue;
        }
        // no mistake in this word
        if ($line[0] == '+') {
            continue;
        }
        // root of word was found
        if ($line[0] == '?') {
            continue;
        }
        // word was guessed
        if (empty($line)) {
            // empty line -> new source line
            $lcnt--;
            continue;
        }
        // now get the misspelled words
        if (preg_match('/^& ([^ ]+) (\\d+) (\\d+): (.*)/', $line, $match)) {
            // match with suggestions
            $word = $match[1];
            $off = $match[3] - 1;
            $sug = split(', ', $match[4]);
        } elseif (preg_match('/^# ([^ ]+) (\\d+)/', $line, $match)) {
            // match without suggestions
            $word = $match[1];
            $off = $match[2] - 1;
            $sug = null;
        } else {
            // couldn't parse output
            print '2';
            print "The spellchecker output couldn't be parsed.\n";
            print "Line {$i}:" . $line;
            return;
        }
        $misspell = true;
        //aspell < 0.60 returns singlebyte offsets
        if ($spell->version >= 600) {
            $len = utf8_strlen($word);
            $data[$lcnt] = utf8_substr_replace($data[$lcnt], spell_formatword($word, $sug), $off, $len);
        } else {
            $len = strlen($word);
            $data[$lcnt] = substr_replace($data[$lcnt], spell_formatword($word, $sug), $off, $len);
        }
    }
    //end of output parsing
    // the first char returns the spell info
    if ($misspell) {
        $string = '1' . join('<br />', $data);
    } else {
//.........这里部分代码省略.........
开发者ID:splitbrain,项目名称:dokuwiki-plugin-spellcheck,代码行数:101,代码来源:spellcheck.php


示例8: autoTag

 /**
  * Inserts tag links into an HTML-formatted text.
  *
  * @param string $html
  * @param array $tags
  * @param array $options
  */
 public static function autoTag($html, array $tagsOrTexts, array &$options = array())
 {
     if (empty($tagsOrTexts)) {
         return $html;
     }
     $html = strval($html);
     $tagTexts = Tinhte_XenTag_Helper::getTextsFromTagsOrTexts($tagsOrTexts);
     // prepare the options
     $onceOnly = empty($options['onceOnly']) ? false : true;
     $options['autoTagged'] = array();
     // reset this
     // sort tags with the longest one first
     // since 1.0.3
     usort($tagTexts, array(__CLASS__, '_autoTag_sortTagsByLength'));
     foreach ($tagTexts as $tagText) {
         $offset = 0;
         $tagLength = utf8_strlen($tagText);
         while (true) {
             $pos = Tinhte_XenTag_Helper::utf8_stripos($html, $tagText, $offset);
             if ($pos !== false) {
                 // the tag has been found
                 if (!self::_autoTag_isBetweenHtmlTags($html, $pos) and self::_autoTag_hasValidCharacterAround($html, $pos, $tagText)) {
                     // and it's not between HTML tags,
                     // with good surrounding characters
                     // start replacing
                     $template = new XenForo_Template_Public('tinhte_xentag_bb_code_tag_tag');
                     $template->setParam('tag', $tagText);
                     $template->setParam('displayText', utf8_substr($html, $pos, $tagLength));
                     $replacement = $template->render();
                     $html = utf8_substr_replace($html, $replacement, $pos, $tagLength);
                     // sondh@2012-09-20
                     // keep track of the auto tagged tags
                     $options['autoTagged'][$tagText][$pos] = $replacement;
                     $offset = $pos + utf8_strlen($replacement);
                     if ($onceOnly) {
                         // auto link only once per tag
                         // break the loop now
                         break;
                         // while (true)
                     }
                 } else {
                     $offset = $pos + $tagLength;
                 }
             } else {
                 // no match has been found, stop working with this tag
                 break;
                 // while (true)
             }
         }
     }
     return $html;
 }
开发者ID:Sywooch,项目名称:forums,代码行数:59,代码来源:Integration.php


示例9: snippet

 /**
  * @param string $string
  * @param int $maxLength
  * @param array $options
  *
  * @return string
  */
 public static function snippet($string, $maxLength = 0, array $options = array())
 {
     $options = array_merge(array('previewBreakBbCode' => 'prbreak', 'ellipsis' => '…'), $options);
     if (!empty($options['previewBreakBbCode']) && preg_match(sprintf('#\\[%1$s\\](?<preview>.*)\\[/%1$s\\]#', preg_quote($options['previewBreakBbCode'], '#')), $string, $matches, PREG_OFFSET_CAPTURE)) {
         // preview break bbcode found
         if (!empty($matches['preview'][0])) {
             // preview text specified, use it directly
             $string = $matches['preview'][0];
             $maxLength = 0;
         } else {
             // use content before the found bbcode to continue
             $string = substr($string, 0, $matches[0][1]);
             $maxLength = 0;
         }
     }
     $snippet = XenForo_Template_Helper_Core::callHelper('snippet', array($string, $maxLength, $options));
     // TODO: find better way to avoid having to call this
     $snippet = htmlspecialchars_decode($snippet);
     if ($maxLength == 0 || $maxLength > utf8_strlen($string)) {
         return $snippet;
     }
     $offset = 0;
     $stack = array();
     while (true) {
         $startPos = utf8_strpos($snippet, '<', $offset);
         if ($startPos !== false) {
             $endPos = utf8_strpos($snippet, '>', $startPos);
             if ($endPos === false) {
                 // we found a partial open tag, best to delete the whole thing
                 $snippet = utf8_substr($snippet, 0, $startPos) . $options['ellipsis'];
                 break;
             }
             $foundLength = $endPos - $startPos - 1;
             $found = utf8_substr($snippet, $startPos + 1, $foundLength);
             $offset = $endPos;
             if (preg_match('#^(?<closing>/?)(?<tag>\\w+)#', $found, $matches)) {
                 $tag = $matches['tag'];
                 $isClosing = !empty($matches['closing']);
                 $isSelfClosing = !$isClosing && utf8_substr($found, $foundLength - 1, 1) === '/';
                 if ($isClosing) {
                     $lastInStack = null;
                     if (count($stack) > 0) {
                         $lastInStack = array_pop($stack);
                     }
                     if ($lastInStack !== $tag) {
                         // found tag does not match the one in stack
                         $replacement = '';
                         // first we have to close the one in stack
                         if ($lastInStack !== null) {
                             $replacement .= sprintf('</%s>', $tag);
                         }
                         // then we have to self close the found tag
                         $replacement .= utf8_substr($snippet, $startPos, $endPos - $startPos - 1);
                         $replacement .= '/>';
                         // do the replacement
                         $snippet = utf8_substr_replace($snippet, $replacement, $startPos, $endPos - $startPos);
                         $offset = $startPos + utf8_strlen($snippet);
                     }
                 } elseif ($isSelfClosing) {
                     // do nothing
                 } else {
                     // is opening tag
                     $stack[] = $tag;
                 }
             }
         } else {
             break;
         }
     }
     while (!empty($stack)) {
         $snippet .= sprintf('</%s>', array_pop($stack));
     }
     $snippet = utf8_trim($snippet);
     if ($snippet === '') {
         // this is bad...
         // happens if the $maxLength is too low and for some reason the very first tag cannot finish
         $snippet = utf8_trim(strip_tags($string));
         if ($snippet !== '') {
             $snippet = XenForo_Template_Helper_Core::callHelper('snippet', array($snippet, $maxLength, $options));
         } else {
             // this is super bad...
             // the string is one big html tag and it is too damn long
             $snippet = $options['ellipsis'];
         }
     }
     return $snippet;
 }
开发者ID:maitandat1507,项目名称:DevHelper,代码行数:94,代码来源:Html.php


示例10: pun_tags_parse_string

function pun_tags_parse_string($text)
{
    global $lang_pun_tags;
    if (utf8_strlen(forum_trim($text)) > 100) {
        message($lang_pun_tags['Count error']);
    }
    // Remove symbols and multiple whitespace
    $text = preg_replace('/[\'\\^\\$&\\(\\)<>`"\\|@_\\?%~\\+\\[\\]{}:=\\/#\\\\;!\\*\\.]+/', '', preg_replace('/[\\s]+/', ' ', $text));
    $text = censor_words($text);
    $text = explode(',', $text);
    $results = array();
    foreach ($text as $tag) {
        $tmp_tag = utf8_trim($tag);
        if (!empty($tmp_tag)) {
            $results[] = utf8_substr_replace($tmp_tag, '', 50);
        }
    }
    return array_unique($results);
}
开发者ID:torepublicStartpageCode,项目名称:torepublic2,代码行数:19,代码来源:functions.php


示例11: substr_replace

 public static function substr_replace($str, $repl, $start, $length = null)
 {
     if ($length === false) {
         return utf8_substr_replace($str, $repl, $start);
     } else {
         return utf8_substr_replace($str, $repl, $start, $length);
     }
 }
开发者ID:vanie3,项目名称:appland,代码行数:8,代码来源:string.php


示例12: testLinefeedReplace

 function testLinefeedReplace()
 {
     $str = "Iñ\ntërnâtiônàlizætiøn";
     $replaced = "Iñ\ntërnâtX\nY";
     $this->assertEqual(utf8_substr_replace($str, "X\nY", 9), $replaced);
 }
开发者ID:kidwellj,项目名称:scuttle,代码行数:6,代码来源:utf8_substr_replace.test.php


示例13: getBlogsReviews


//.........这里部分代码省略.........
                     $thumb = '';
                 }
                 if (!isset($comment['text'])) {
                     $comment['text'] = '';
                 }
                 $text = '';
                 if ($comment['text'] != '') {
                     $flag_desc = 'none';
                     if ($thislist['desc_symbols'] != '') {
                         $amount = $thislist['desc_symbols'];
                         $flag_desc = 'symbols';
                     }
                     if ($thislist['desc_words'] != '') {
                         $amount = $thislist['desc_words'];
                         $flag_desc = 'words';
                     }
                     if ($thislist['desc_pred'] != '') {
                         $amount = $thislist['desc_pred'];
                         $flag_desc = 'pred';
                     }
                     //if ($flag_desc != 'none')
                     //$comment['text'] = preg_replace('/\[(.*?)\]/', '', $comment['text']);
                     switch ($flag_desc) {
                         case 'symbols':
                             $limit = $amount;
                             $source = strip_tags(html_entity_decode($comment['text'], ENT_QUOTES, 'UTF-8'));
                             $counter = 0;
                             $matches = array();
                             utf8_preg_match_all('/(?:\\[.*\\].*\\[\\/.*\\])|(.)/Usiu', $source, $matches, PREG_OFFSET_CAPTURE);
                             foreach ($matches[1] as $num => $val) {
                                 if (is_array($val)) {
                                     $counter++;
                                     if ($counter == $limit) {
                                         $source = utf8_substr_replace($source, '', $val[1] + 1);
                                         break;
                                     }
                                 }
                             }
                             $text = $source;
                             //$pattern = ('/((.*?)\S){0,' . $amount . '}/isu');
                             //preg_match_all($pattern, strip_tags(html_entity_decode($comment['text'], ENT_QUOTES, 'UTF-8')), $out);
                             //$text = $out[0][0];
                             break;
                         case 'words':
                             $limit = $amount;
                             $source = strip_tags(html_entity_decode($comment['text'], ENT_QUOTES, 'UTF-8'));
                             $counter = 0;
                             $matches = array();
                             utf8_preg_match_all('/(?:\\[.*\\].*\\[\\/.*\\])|(\\x20)/Usiu', $source, $matches, PREG_OFFSET_CAPTURE);
                             foreach ($matches[1] as $num => $val) {
                                 if (is_array($val)) {
                                     $counter++;
                                     if ($counter == $limit) {
                                         $source = utf8_substr_replace($source, '', $val[1] + 1);
                                         break;
                                     }
                                 }
                             }
                             $text = $source;
                             /*
                             								$pattern = ('/((.*?)\x20){0,' . $amount . '}/isu');
                             								preg_match_all($pattern, strip_tags(html_entity_decode($comment['text'], ENT_QUOTES, 'UTF-8')), $out);
                             								$text = $out[0][0];*/
                             break;
                         case 'pred':
                             $limit = $amount;
开发者ID:BulatSa,项目名称:Ctex,代码行数:67,代码来源:blog.php


示例14: substr_replace

 /**
  * UTF-8 aware substr_replace
  * Replace text within a portion of a string
  *
  * @param   string   $str     The haystack
  * @param   string   $repl    The replacement string
  * @param   integer  $start   Start
  * @param   integer  $length  Length (optional)
  *
  * @return  string
  *
  * @see     http://www.php.net/substr_replace
  * @since   11.1
  */
 public static function substr_replace($str, $repl, $start, $length = null)
 {
     // Loaded by library loader
     if ($length === false) {
         return utf8_substr_replace($str, $repl, $start);
     } else {
         return utf8_substr_replace($str, $repl, $start, $length);
     }
 }
开发者ID:nogsus,项目名称:joomla-platform,代码行数:23,代码来源:string.php


示例15: substr_replace

 /**
  * UTF-8 aware substr_replace
  * Replace text within a portion of a string
  *
  * @static
  * @access public
  * @param string the haystack
  * @param string the replacement string
  * @param int start
  * @param int length (optional)
  * @see http://www.php.net/substr_replace
  */
 public static function substr_replace($str, $repl, $start, $length = NULL)
 {
     // loaded by library loader
     if ($length === FALSE) {
         return utf8_substr_replace($str, $repl, $start);
     } else {
         return utf8_substr_replace($str, $repl, $start, $length);
     }
 }
开发者ID:joebushi,项目名称:joomla,代码行数:21,代码来源:string.php


示例16: filterString

 public function filterString($string, array $rendererStates)
 {
     $isString = true;
     if (is_array($string)) {
         // array is our way of marking tag originals prepend/append text
         $isString = false;
         $string = reset($string);
     }
     if ($isString) {
         // checks if the string is an URI of some kind
         $isString = !Zend_Uri::check($string);
     }
     if ($isString) {
         // checks if the parent tag has some strange requirements
         $tagDataStack = $rendererStates['tagDataStack'];
         $lastTagDataStack = array_pop($tagDataStack);
         if ($lastTagDataStack['tag'] === 'hashtag') {
             // well, this is a hashtag already...
             $isString = false;
         } else {
             $parentTagInfo = $this->_parent__getTagRule($lastTagDataStack['tag']);
             if (!empty($parentTagInfo['plainChildren'])) {
                 // parent tag asks for plain children, we should do nothing
                 $isString = false;
             } elseif (!empty($parentTagInfo['stopSmilies']) or !empty($parentTagInfo['stopLineBreakConversion'])) {
                 // parent tag asks for some functionalities disabled, we should disable ourself
                 // too
                 $isString = false;
             }
         }
     }
     if ($isString) {
         $offset = 0;
         while (true) {
             $pos = utf8_strpos($string, '#', $offset);
             if ($pos === false) {
                 break;
             }
             $offset = $pos + 1;
             if ($pos > 0) {
                 $beforeTagText = utf8_substr($string, $pos - 1, 1);
                 if (!preg_match(Tinhte_XenTag_Integration::REGEX_VALID_CHARACTER_AROUND, $beforeTagText)) {
                     // the before character of tag text is not a valid character, dismiss the found
                     // tag text
                     continue;
                 }
             }
             $stringForPregMatch = utf8_substr($string, $pos + 1);
             if (preg_match('/[^a-zA-Z0-9]/', $stringForPregMatch, $matches, PREG_OFFSET_CAPTURE)) {
                 $nonTagTextPos = $matches[0][1];
             } else {
                 // get all of the remaining characters
                 $nonTagTextPos = utf8_strlen($stringForPregMatch);
             }
             $nonTagTextPos += $pos + 1;
             $tagText = utf8_trim(utf8_substr($string, $pos + 1, $nonTagTextPos - 1 - $pos));
             if (utf8_strlen($tagText) < Tinhte_XenTag_Option::get('tagMinLength')) {
                 // too short
                 continue;
             }
             $afterTagText = utf8_substr($string, $nonTagTextPos, 1);
             if (!empty($afterTagText)) {
                 if (!preg_match(Tinhte_XenTag_Integration::REGEX_VALID_CHARACTER_AROUND, $afterTagText)) {
                     // the after character of tag text is not a valid character, dismiss the found
                     // tag text
                     $tagText = '';
                 }
             }
             if (!empty($tagText)) {
                 $this->_Tinhte_XenTag_autoHashtagTexts[Tinhte_XenTag_Helper::getSafeTagTextForSearch($tagText)] = $tagText;
                 // add bb code wrapping
                 $replacement = sprintf('[HASHTAG]#%s[/HASHTAG]', $tagText);
                 $string = utf8_substr_replace($string, $replacement, $pos, $nonTagTextPos - $pos);
                 $pos += utf8_strlen($replacement) - 1;
             }
             $offset = $pos + 1;
         }
     }
     return parent::filterString($string, $rendererStates);
 }
开发者ID:Sywooch,项目名称:forums,代码行数:80,代码来源:AutoHashtag.php


示例17: _filterHashtagsFromMessage

 protected function _filterHashtagsFromMessage($message)
 {
     $bbCodeOpen = '[HASHTAG]';
     $bbCodeClose = '[/HASHTAG]';
     $dbTags = $this->getModelFromCache('Tinhte_XenTag_Model_Tag')->getTagsOfContent('post', $this->get('post_id'));
     $dbTagTexts = Tinhte_XenTag_Helper::getTextsFromTagsOrTexts($dbTags);
     $dbSafeTags = Tinhte_XenTag_Helper::getSafeTagsTextArrayForSearch($dbTagTexts);
     $offset = 0;
     while (true) {
         $posOpen = Tinhte_XenTag_Helper::utf8_stripos($message, $bbCodeOpen, $offset);
         if ($posOpen === false) {
             break;
         }
         $posClose = Tinhte_XenTag_Helper::utf8_stripos($message, $bbCodeClose, $posOpen);
         if ($posClose === false) {
             break;
         }
         $offset = $posOpen + 1;
         $posTagTextOffset = $posOpen + utf8_strlen($bbCodeOpen) + 1;
         $posTagTextLength = $posClose - $posTagTextOffset;
         $posTagText = utf8_substr($message, $posTagTextOffset, $posTagTextLength);
         $posSafeTag = Tinhte_XenTag_Helper::getSafeTagTextForSearch($posTagText);
         if (!in_array($posSafeTag, $dbSafeTags)) {
             $message = utf8_substr_replace($message, '#' . $posTagText, $posOpen, $posClose + utf8_strlen($bbCodeClose) - $posOpen);
         }
     }
     return $message;
 }
开发者ID:Sywooch,项目名称:forums,代码行数:28,代码来源:Post.php



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
PHP utf8_to_ascii函数代码示例发布时间:2022-05-23
下一篇:
PHP utf8_substr函数代码示例发布时间:2022-05-23
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap