本文整理汇总了PHP中utf8_trim函数的典型用法代码示例。如果您正苦于以下问题:PHP utf8_trim函数的具体用法?PHP utf8_trim怎么用?PHP utf8_trim使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了utf8_trim函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: _init_search_query_object
function _init_search_query_object()
{
$request = request::instance();
if ($search_query = utf8_trim($request->get_attribute('search_query'))) {
$this->query_object->add(search_text_normalizer::process($search_query));
}
}
示例2: getMessageText
public function getMessageText($inputName, XenForo_Input $input, $htmlCharacterLimit = -1)
{
$messageText = parent::getMessageText($inputName, $input, $htmlCharacterLimit);
if (utf8_trim($messageText) === 'lipsum') {
$lipsum = @file_get_contents('http://www.lipsum.com/feed/json');
if (!empty($lipsum)) {
$lipsum = @json_decode($lipsum, true);
if (!empty($lipsum['feed']['lipsum'])) {
$messageText = sprintf("%s\n\nBy [URL=%s]%s[/URL]", $lipsum['feed']['lipsum'], $lipsum['feed']['creditlink'], $lipsum['feed']['creditname']);
}
}
}
return $messageText;
}
示例3: get_search_query_object
function get_search_query_object()
{
if ($this->query_object) {
return $this->query_object;
}
$request = request::instance();
if (!($search_query = utf8_trim($request->get_attribute('search_query')))) {
return null;
}
$this->query_object = new search_query();
$search_query = search_text_normalizer::process($search_query);
$words = explode(' ', $search_query);
foreach ($words as $word) {
$this->query_object->add($word);
}
return $this->query_object;
}
示例4: parse_var_file
/**
* Parses a var file into a data structure. Used in conjunction with an
* Importtag
*/
function parse_var_file($filename)
{
$result = array();
$raw_lines = file($filename);
while (list(, $line) = each($raw_lines)) {
$equal_pos = utf8_strpos($line, '=');
if ($equal_pos === false) {
$result[utf8_trim($line)] = null;
} else {
$key = utf8_trim(utf8_substr($line, 0, $equal_pos));
if (utf8_strlen($key) > 0) {
$result[$key] = utf8_trim(utf8_substr($line, $equal_pos + 1));
}
}
}
return $result;
}
示例5: substrs
/**
* 双字节字符截取
*
* @param string $content
* @param int $length
* @return string
*/
function substrs($content, $length)
{
if (!defined('CFG_CHARSET')) {
define('CFG_CHARSET', 'utf-8');
}
if ($length && strlen($content) > $length) {
if (CFG_CHARSET != 'utf-8') {
$retstr = '';
for ($i = 0; $i < $length - 2; $i++) {
$retstr .= ord($content[$i]) > 127 ? $content[$i] . $content[++$i] : $content[$i];
}
return $retstr . ' ..';
} else {
return utf8_trim(substr($content, 0, $length * 3));
}
}
return $content;
}
示例6: utf8_basename
/**
* Returns filename component of path
*
* @author Lars Knickrehm <mail@lars-sh.de>
* @category Library
* @copyright Copyright © 2009 Lars Knickrehm
* @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License
* @link http://php.net/manual/function.basename.php
* @package UTF-8
* @param string $path A path. Both slash (/) and backslash (\) are used as directory separator character.
* @param string $suffix If the filename ends in suffix this will also be cut off.
* @return string Base name of the given path
* @since Version 0.5.0
* @version 0.5.0
*/
function utf8_basename($path, $suffix = '')
{
// Change backslash (\) to slash (/)
$path = utf8_trim(strtr($path, array('\\' => '/')), '/');
// Get basename
$i = utf8_strrpos($path, '/');
if ($i !== false) {
$path = utf8_substr($path, $i + 1);
}
// Handle suffix
if ($suffix !== '') {
$position = utf8_strrpos($path, $suffix);
if ($position !== false) {
$path = utf8_substr($path, 0, $position);
}
}
return $path;
}
示例7: process
function process($content)
{
$content = utf8_strtolower($content);
$content = utf8_str_replace("\n", ' ', $content);
$content = utf8_str_replace("\t", ' ', $content);
$content = utf8_str_replace("\r", ' ', $content);
$search = array("'<script[^>]*?>.*?</script>'si", "'<[\\/\\!]*?[^<>]*?>'si", "'([\r\n])[\\s]+'");
$replace = array('', ' ', ' ');
$content = preg_replace($search, $replace, $content);
$content = preg_replace("#(\\.){2,}#", ' ', $content);
$content = preg_replace("#^\\.#", ' ', $content);
$content = preg_replace("#\\s\\.#", ' ', $content);
$content = preg_replace("#\\.\\s#", ' ', $content);
$content = preg_replace("#\\.\$#", ' ', $content);
//non utf8 chars(�,�)
$content = preg_replace("#(\\s|^)(\"|'|`|�|�)(\\w)#", '\\1\\3', $content);
$content = preg_replace("#(\\w)(\"|'|`|�|�)(\\s|\$)#u", '\\1\\3', $content);
$content = utf8_str_replace(" ", ' ', $content);
$content = utf8_str_replace(":", ' ', $content);
$content = utf8_str_replace(",", ' ', $content);
$content = utf8_str_replace(";", ' ', $content);
$content = utf8_str_replace("(", ' ', $content);
$content = utf8_str_replace(")", ' ', $content);
$content = utf8_str_replace("-", ' ', $content);
$content = utf8_str_replace("+", ' ', $content);
$content = utf8_str_replace("/", ' ', $content);
$content = utf8_str_replace("!", ' ', $content);
$content = utf8_str_replace("?", ' ', $content);
$content = utf8_str_replace("[", ' ', $content);
$content = utf8_str_replace("]", ' ', $content);
$content = utf8_str_replace("\$", ' ', $content);
$content = utf8_str_replace("\\", ' ', $content);
$content = utf8_str_replace("<", ' ', $content);
$content = utf8_str_replace(">", ' ', $content);
$content = utf8_str_replace("*", ' ', $content);
$content = utf8_trim(preg_replace("~\\s+~u", ' ', $content));
return $content;
}
示例8: pun_trim
function pun_trim($str, $charlist = false)
{
return is_string($str) ? utf8_trim($str, $charlist) : '';
}
示例9: userorg_update_by_name
/**
* Assign user to organization AND Try to create new organization if it doesn't exist yet
*
* @param object User
* @param string Organization name
* @param string Organization role
*/
function userorg_update_by_name(&$User, $org_name, $org_role = '')
{
$org_name = utf8_trim($org_name);
if (empty($org_name)) {
// Don't update an user organization with empty name:
return;
}
if (is_null($this->userorgs)) {
// Initialize array to keep what organizations should be assigned to the user:
$this->userorgs = array();
}
// Get organization ID by name AND save it in array to update after user insertion:
$org_ID = $this->userorg_get_by_name($org_name);
$this->userorgs[$org_ID] = $org_role;
}
示例10: get_user_avatar_url
if ($is_logged_in) {
if ($User->ID == $current_User->ID && !$User->has_avatar()) {
// If user hasn't an avatar, add a link to go for uploading of avatar
$avatar_imgtag = '<a href="' . get_user_avatar_url() . '">' . $avatar_imgtag . '</a>';
}
}
echo $params['profile_avatar_before'] . $avatar_imgtag . $params['profile_avatar_after'];
// First Last Names:
$first_last_name = '';
if ($Settings->get('firstname_editing') != 'hidden' && $User->get('firstname') != '') {
$first_last_name .= $User->get('firstname');
}
if ($Settings->get('lastname_editing') != 'hidden' && $User->get('lastname') != '') {
$first_last_name .= ' ' . $User->get('lastname');
}
$first_last_name = utf8_trim($first_last_name);
if (!empty($first_last_name)) {
// Display first last name of it is not empty
echo '<h1>' . $first_last_name . '</h1>';
}
// Nickname:
if ($Settings->get('nickname_editing') != 'hidden' && $User->get('nickname') != '') {
echo '<h2>' . $User->get('nickname') . '</h2>';
}
// Login:
echo '<h2 class="text-muted">' . $User->get('login') . '</h2>';
echo '<hr class="profile_separator" />' . "\n";
// Gender & age group:
$gender_age_group = $User->get_gender();
if (!empty($User->age_min) || !empty($User->age_max)) {
if (!empty($gender_age_group)) {
示例11: trim
/**
* UTF-8 aware replacement for trim()
*
* Strip whitespace (or other characters) from the beginning and end of a string. You only need to use this if you are supplying the charlist
* optional arg and it contains UTF-8 characters. Otherwise trim will work normally on a UTF-8 string
*
* @param string $str The string to be trimmed
* @param string $charlist The optional charlist of additional characters to trim
*
* @return string The trimmed string
*
* @see http://www.php.net/trim
* @since 1.3.0
*/
public static function trim($str, $charlist = false)
{
if (empty($charlist) && $charlist !== false) {
return $str;
}
if ($charlist === false) {
return utf8_trim($str);
}
return utf8_trim($str, $charlist);
}
示例12: getNormalizedTagText
public static function getNormalizedTagText($tagText)
{
$tagText = utf8_trim($tagText);
$tagText = utf8_strtolower($tagText);
return $tagText;
}
示例13: processEditProjectForm
function processEditProjectForm()
{
global $manager;
$id = $_POST['id'];
$title = $_POST['title'];
$slug = empty($_POST['slug']) ? $manager->clerk->simple_name($title) : $_POST['slug'];
$oldSlug = $_POST['oldslug'];
$now = getdate();
$date = mktime($now["hours"], $now["minutes"], $now["seconds"], $_POST["date_month"], $_POST["date_day"], $_POST["date_year"]);
$tags = $_POST['tags'];
$publish = $_POST['publish'];
$paths = $manager->getSetting("projects_path");
$paths = array('path' => $paths['data1'], 'url' => $paths['data2']);
if ($_POST['submit'] == "save") {
if ($manager->clerk->query_countRows("projects", "WHERE slug= '{$slug}' AND id != '{$id}'") >= 1) {
$manager->message(0, false, 'A project with the simple name/slug <em>"' . $slug . '"</em> already exists! Please choose a new one.');
return false;
}
if ($manager->clerk->query_edit("projects", "title= '{$title}', slug= '{$slug}', date= '{$date}', publish= '{$publish}'", "WHERE id= '{$id}'")) {
$manager->message(1, false, "Project <em>{$title}</em> saved!");
// Handle tags...
if (!empty($tags)) {
$tags = explode(",", $tags);
$total = count($tags);
$manager->clerk->query_delete("projects_to_tags", "WHERE projectid= '{$id}'");
$count = 0;
foreach ($tags as $c) {
$count++;
$query .= "('" . utf8_trim($c) . "', '{$id}')";
$query .= $count == $total ? "" : ", ";
}
$manager->clerk->query_insert("projects_to_tags", "tag, projectid", $query, true);
} else {
$manager->clerk->query_delete("projects_to_tags", "WHERE projectid= '{$id}'");
}
// Handle renaming
if ($slug != $oldSlug) {
rename($paths['path'] . $oldSlug, $paths['path'] . $slug);
}
} else {
$manager->message(0, true, "This project could not be saved!");
}
}
}
示例14: 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;
}
示例15: score_tags
/**
* Return a search score for the given text and search keywords
*
* @param string Text to score
* @param string The search keywords to score by
* @param integer Score multiplier
* @return integer Result score
*/
function score_tags($tag_name, $search_term, $score_weight = 4)
{
$score = 0.0;
$scores_map = array();
if ($tag_name == utf8_trim($search_term)) {
// We use only EXACT match for post tags:
$score = $score_weight;
$scores_map['tags'] = $score;
}
return array('score' => $score, 'score_weight' => $score_weight, 'map' => $scores_map);
}