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


PHP core_text::substr方法代码示例

本文整理汇总了PHP中core_text::substr方法的典型用法代码示例。如果您正苦于以下问题:PHP core_text::substr方法的具体用法?PHP core_text::substr怎么用?PHP core_text::substr使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在core_text的用法示例。


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

示例1: mb_substr

/**
 * Performs a multi-byte safe substr() operation based on number of characters.
 * Position is counted from the beginning of str. First character's position is
 * 0. Second character position is 1, and so on.
 *
 * @param string $str      The string to extract the substring from.
 * @param int    $start    If start is non-negative, the returned string will
 *                         start at the start'th position in string, counting
 *                         from zero. For instance, in the string 'abcdef',
 *                         the character at position 0 is 'a', the character
 *                         at position 2 is 'c', and so forth.
 * @param int    $length   Maximum number of characters to use from str. If
 *                         omitted or NULL is passed, extract all characters
 *                         to the end of the string.
 * @param string $encoding The encoding parameter is the character encoding.
 *                         If it is omitted, the internal character encoding
 *                         value will be used.
 *
 * @return string The portion of str specified by the start and length parameters.
 */
function mb_substr($str, $start, $length = null, $encoding = null)
{
    if ($encoding === null) {
        $encoding = mb_internal_encoding();
    }
    return \core_text::substr($str, $start, $length, $encoding);
}
开发者ID:gabrielrosset,项目名称:moodle,代码行数:27,代码来源:override.php

示例2: col_name

 /**
  * Determine output for the name column.
  *
  * @param stdClass   $recording The recording row being worked on.
  * @return string    The output to display.
  */
 public function col_name($recording)
 {
     if (\core_text::strlen($recording->name) > 60) {
         return \core_text::substr($recording->name, 0, 55) . '…';
     }
     return $recording->name;
 }
开发者ID:collegemathieu,项目名称:moodle-mod_webexactivity,代码行数:13,代码来源:admin_recordings_table.php

示例3: block_course_overview_update_myorder

/**
 * Sets user course sorting preference in course_overview block
 *
 * @param array $sortorder list of course ids
 */
function block_course_overview_update_myorder($sortorder)
{
    $value = implode(',', $sortorder);
    if (core_text::strlen($value) > 1333) {
        // The value won't fit into the user preference. Remove courses in the end of the list (mostly likely user won't even notice).
        $value = preg_replace('/,[\\d]*$/', '', core_text::substr($value, 0, 1334));
    }
    set_user_preference('course_overview_course_sortorder', $value);
}
开发者ID:evltuma,项目名称:moodle,代码行数:14,代码来源:locallib.php

示例4: get_label_name

/**
 * @uses LABEL_MAX_NAME_LENGTH
 * @param object $label
 * @return string
 */
function get_label_name($label)
{
    $name = strip_tags(format_string($label->intro, true));
    if (core_text::strlen($name) > LABEL_MAX_NAME_LENGTH) {
        $name = core_text::substr($name, 0, LABEL_MAX_NAME_LENGTH) . "...";
    }
    if (empty($name)) {
        // arbitrary name
        $name = get_string('modulename', 'label');
    }
    return $name;
}
开发者ID:sumitnegi933,项目名称:Moodle_lms_New,代码行数:17,代码来源:lib.php

示例5: get_trainingevent_name

/**
 * @uses COURSECLASSROOM_MAX_NAME_LENGTH
 * @param object $trainingevent
 * @return string
 */
function get_trainingevent_name($trainingevent)
{
    $name = strip_tags(format_string($trainingevent->name, true));
    if (core_text::strlen($name) > COURSECLASSROOM_MAX_NAME_LENGTH) {
        $name = core_text::substr($name, 0, COURSECLASSROOM_MAX_NAME_LENGTH) . "...";
    }
    if (empty($name)) {
        // Arbitrary name.
        $name = get_string('modulename', 'trainingevent');
    }
    return $name;
}
开发者ID:sumitnegi933,项目名称:Moodle_lms_New,代码行数:17,代码来源:lib.php

示例6: send_message

 /**
  * Processes the message and sends a notification via airnotifier
  *
  * @param stdClass $eventdata the event data submitted by the message sender plus $eventdata->savedmessageid
  * @return true if ok, false if error
  */
 public function send_message($eventdata)
 {
     global $CFG;
     require_once $CFG->libdir . '/filelib.php';
     if (!empty($CFG->noemailever)) {
         // Hidden setting for development sites, set in config.php if needed.
         debugging('$CFG->noemailever active, no airnotifier message sent.', DEBUG_MINIMAL);
         return true;
     }
     // Skip any messaging suspended and deleted users.
     if ($eventdata->userto->auth === 'nologin' or $eventdata->userto->suspended or $eventdata->userto->deleted) {
         return true;
     }
     // Site id, to map with Moodle Mobile stored sites.
     $siteid = md5($CFG->wwwroot . $eventdata->userto->username);
     // Mandatory notification data that need to be sent in the payload. They have variable length.
     // We need to take them in consideration to calculate the maximum message size.
     $notificationdata = array("site" => $siteid, "type" => $eventdata->component . '_' . $eventdata->name, "device" => "xxxxxxxxxx", "notif" => "x", "userfrom" => !empty($eventdata->userfrom) ? fullname($eventdata->userfrom) : '');
     // Calculate the size of the message knowing Apple payload must be lower than 256 bytes.
     // Airnotifier using few bytes of the payload, we must limit our message to even less characters.
     $maxmsgsize = 205 - core_text::strlen(json_encode($notificationdata));
     $message = s($eventdata->smallmessage);
     // If the message size is too big make it shorter.
     if (core_text::strlen($message) >= $maxmsgsize) {
         // Cut the message to the maximum possible size. -4 for the the ending 3 dots (...).
         $message = core_text::substr($message, 0, $maxmsgsize - 4);
         // We need to check when the message is "escaped" then the message is not too long.
         $encodedmsgsize = core_text::strlen(json_encode($message));
         if ($encodedmsgsize > $maxmsgsize) {
             $totalescapedchar = $encodedmsgsize - core_text::strlen($message);
             // Cut the message to the maximum possible size (taking the escaped character in account).
             $message = core_text::substr($message, 0, $maxmsgsize - 4 - $totalescapedchar);
         }
         $message = $message . '...';
     }
     // We are sending to message to all devices.
     $airnotifiermanager = new message_airnotifier_manager();
     $devicetokens = $airnotifiermanager->get_user_devices($CFG->airnotifiermobileappname, $eventdata->userto->id);
     foreach ($devicetokens as $devicetoken) {
         if (!$devicetoken->enable) {
             continue;
         }
         // Sending the message to the device.
         $serverurl = $CFG->airnotifierurl . ':' . $CFG->airnotifierport . '/notification/';
         $header = array('Accept: application/json', 'X-AN-APP-NAME: ' . $CFG->airnotifierappname, 'X-AN-APP-KEY: ' . $CFG->airnotifieraccesskey);
         $curl = new curl();
         $curl->setHeader($header);
         $params = array('alert' => $message, 'date' => !empty($eventdata->timecreated) ? $eventdata->timecreated : time(), 'site' => $siteid, 'type' => $eventdata->component . '_' . $eventdata->name, 'userfrom' => !empty($eventdata->userfrom) ? fullname($eventdata->userfrom) : '', 'device' => $devicetoken->platform, 'notif' => !empty($eventdata->notification) ? '1' : '0', 'token' => $devicetoken->pushid);
         $resp = $curl->post($serverurl, $params);
     }
     return true;
 }
开发者ID:sumitnegi933,项目名称:Moodle_lms_New,代码行数:58,代码来源:message_output_airnotifier.php

示例7: set_sheettitle

 /**
  * Set the title of the worksheet inside a spreadsheet
  *
  * For some formats this will be ignored.
  *
  * @param string $title
  */
 public function set_sheettitle($title)
 {
     if (!$title) {
         return;
     }
     // Replace any characters in the name that ODS cannot cope with.
     $title = strtr(trim($title, "'"), '[]*/\\?:', '       ');
     // Shorten the title if necessary.
     $title = \core_text::substr($title, 0, 31);
     // After the substr, we might now have a single quote on the end.
     $title = trim($title, "'");
     $this->sheettitle = $title;
 }
开发者ID:evltuma,项目名称:moodle,代码行数:20,代码来源:writer.php

示例8: validation

 function validation($data, $files)
 {
     $errors = array();
     foreach ($data as $key => $value) {
         if ($value == 'null') {
             if (core_text::substr($key, 0, 2) == 'of') {
                 $errors[$key] = get_string('overallfairnessrequired', 'mod_emarking');
             } else {
                 $errors[$key] = get_string('expectationrealityrequired', 'mod_emarking');
             }
         }
     }
     return $errors;
 }
开发者ID:eduagdo,项目名称:emarking,代码行数:14,代码来源:justice_form_criterion.php

示例9: save_usage

 public function save_usage($preferredbehaviour, $attempt, $qas, $quizlayout)
 {
     global $OUTPUT;
     $missing = array();
     $layout = explode(',', $attempt->layout);
     $questionkeys = array_combine(array_values($layout), array_keys($layout));
     $this->set_quba_preferred_behaviour($attempt->uniqueid, $preferredbehaviour);
     $i = 0;
     foreach (explode(',', $quizlayout) as $questionid) {
         if ($questionid == 0) {
             continue;
         }
         $i++;
         if (!array_key_exists($questionid, $qas)) {
             $missing[] = $questionid;
             $layout[$questionkeys[$questionid]] = $questionid;
             continue;
         }
         $qa = $qas[$questionid];
         $qa->questionusageid = $attempt->uniqueid;
         $qa->slot = $i;
         if (core_text::strlen($qa->questionsummary) > question_bank::MAX_SUMMARY_LENGTH) {
             // It seems some people write very long quesions! MDL-30760
             $qa->questionsummary = core_text::substr($qa->questionsummary, 0, question_bank::MAX_SUMMARY_LENGTH - 3) . '...';
         }
         $this->insert_record('question_attempts', $qa);
         $layout[$questionkeys[$questionid]] = $qa->slot;
         foreach ($qa->steps as $step) {
             $step->questionattemptid = $qa->id;
             $this->insert_record('question_attempt_steps', $step);
             foreach ($step->data as $name => $value) {
                 $datum = new stdClass();
                 $datum->attemptstepid = $step->id;
                 $datum->name = $name;
                 $datum->value = $value;
                 $this->insert_record('question_attempt_step_data', $datum, false);
             }
         }
     }
     $this->set_quiz_attempt_layout($attempt->uniqueid, implode(',', $layout));
     if ($missing) {
         $message = "Question sessions for questions " . implode(', ', $missing) . " were missing when upgrading question usage {$attempt->uniqueid}.";
         echo $OUTPUT->notification($message);
     }
 }
开发者ID:evltuma,项目名称:moodle,代码行数:45,代码来源:upgradelib.php

示例10: validation

 public function validation($data, $files)
 {
     global $DB, $CFG;
     $errors = parent::validation($data, $files);
     $instance = $this->instance;
     if ($instance->password !== '') {
         if ($data['guestpassword'] !== $instance->password) {
             $plugin = enrol_get_plugin('guest');
             if ($plugin->get_config('showhint')) {
                 $hint = core_text::substr($instance->password, 0, 1);
                 $errors['guestpassword'] = get_string('passwordinvalidhint', 'enrol_guest', $hint);
             } else {
                 $errors['guestpassword'] = get_string('passwordinvalid', 'enrol_guest');
             }
         }
     }
     return $errors;
 }
开发者ID:evltuma,项目名称:moodle,代码行数:18,代码来源:locallib.php

示例11: rfc2445_fold

function rfc2445_fold($string)
{
    if (core_text::strlen($string, 'utf-8') <= RFC2445_FOLDED_LINE_LENGTH) {
        return $string;
    }
    $retval = '';
    $i = 0;
    $len_count = 0;
    //multi-byte string, get the correct length
    $section_len = core_text::strlen($string, 'utf-8');
    while ($len_count < $section_len) {
        //get the current portion of the line
        $section = core_text::substr($string, $i * RFC2445_FOLDED_LINE_LENGTH, RFC2445_FOLDED_LINE_LENGTH, 'utf-8');
        //increment the length we've processed by the length of the new portion
        $len_count += core_text::strlen($section, 'utf-8');
        /* Add the portion to the return value, terminating with CRLF.HTAB
           As per RFC 2445, CRLF.HTAB will be replaced by the processor of the 
           data */
        $retval .= $section . RFC2445_CRLF . substr(RFC2445_WSP, 0, 1);
        $i++;
    }
    return $retval;
}
开发者ID:evltuma,项目名称:moodle,代码行数:23,代码来源:iCalendar_rfc2445.php

示例12: bootstrap_process_message

 protected function bootstrap_process_message($message)
 {
     global $DB;
     $messagecontent = new stdClass();
     if ($message->notification) {
         $messagecontent->text = get_string('unreadnewnotification', 'message');
     } else {
         if ($message->fullmessageformat == FORMAT_HTML) {
             $message->smallmessage = html_to_text($message->smallmessage);
         }
         if (core_text::strlen($message->smallmessage) > 15) {
             $messagecontent->text = core_text::substr($message->smallmessage, 0, 15) . '...';
         } else {
             $messagecontent->text = $message->smallmessage;
         }
     }
     if (time() - $message->timecreated <= 3600 * 3) {
         $messagecontent->date = format_time(time() - $message->timecreated);
     } else {
         $messagecontent->date = userdate($message->timecreated, get_string('strftimetime', 'langconfig'));
     }
     $messagecontent->from = $DB->get_record('user', array('id' => $message->useridfrom));
     return $messagecontent;
 }
开发者ID:noelchavez,项目名称:moodle-theme_elegance,代码行数:24,代码来源:core_renderer.php

示例13: test_replace_all_text

 public function test_replace_all_text()
 {
     $DB = $this->tdb;
     $dbman = $DB->get_manager();
     if (!$DB->replace_all_text_supported()) {
         $this->markTestSkipped($DB->get_name() . ' does not support replacing of texts');
     }
     $table = $this->get_test_table();
     $tablename = $table->getName();
     $table->add_field('id', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, XMLDB_SEQUENCE, null);
     $table->add_field('name', XMLDB_TYPE_CHAR, '20', null, null);
     $table->add_field('intro', XMLDB_TYPE_TEXT, 'big', null, null);
     $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id'));
     $dbman->create_table($table);
     $id1 = (string) $DB->insert_record($tablename, array('name' => null, 'intro' => null));
     $id2 = (string) $DB->insert_record($tablename, array('name' => '', 'intro' => ''));
     $id3 = (string) $DB->insert_record($tablename, array('name' => 'xxyy', 'intro' => 'vvzz'));
     $id4 = (string) $DB->insert_record($tablename, array('name' => 'aa bb aa bb', 'intro' => 'cc dd cc aa'));
     $id5 = (string) $DB->insert_record($tablename, array('name' => 'kkllll', 'intro' => 'kkllll'));
     $expected = $DB->get_records($tablename, array(), 'id ASC');
     $columns = $DB->get_columns($tablename);
     $DB->replace_all_text($tablename, $columns['name'], 'aa', 'o');
     $result = $DB->get_records($tablename, array(), 'id ASC');
     $expected[$id4]->name = 'o bb o bb';
     $this->assertEquals($expected, $result);
     $DB->replace_all_text($tablename, $columns['intro'], 'aa', 'o');
     $result = $DB->get_records($tablename, array(), 'id ASC');
     $expected[$id4]->intro = 'cc dd cc o';
     $this->assertEquals($expected, $result);
     $DB->replace_all_text($tablename, $columns['name'], '_', '*');
     $DB->replace_all_text($tablename, $columns['name'], '?', '*');
     $DB->replace_all_text($tablename, $columns['name'], '%', '*');
     $DB->replace_all_text($tablename, $columns['intro'], '_', '*');
     $DB->replace_all_text($tablename, $columns['intro'], '?', '*');
     $DB->replace_all_text($tablename, $columns['intro'], '%', '*');
     $result = $DB->get_records($tablename, array(), 'id ASC');
     $this->assertEquals($expected, $result);
     $long = '1234567890123456789';
     $DB->replace_all_text($tablename, $columns['name'], 'kk', $long);
     $result = $DB->get_records($tablename, array(), 'id ASC');
     $expected[$id5]->name = core_text::substr($long . 'llll', 0, 20);
     $this->assertEquals($expected, $result);
     $DB->replace_all_text($tablename, $columns['intro'], 'kk', $long);
     $result = $DB->get_records($tablename, array(), 'id ASC');
     $expected[$id5]->intro = $long . 'llll';
     $this->assertEquals($expected, $result);
 }
开发者ID:EmmanuelYupit,项目名称:educursos,代码行数:47,代码来源:dml_test.php

示例14: tag_print_user_box

/**
 * Prints an individual user box
 *
 * @deprecated since 3.1
 * @param user_object  $user  (contains the following fields: id, firstname, lastname and picture)
 * @param bool         $return if true return html string
 * @return string|null a HTML string or null if this function does the output
 */
function tag_print_user_box($user, $return = false)
{
    global $CFG, $OUTPUT;
    debugging('Function tag_print_user_box() is deprecated without replacement. ' . 'See core_user_renderer for similar code.', DEBUG_DEVELOPER);
    $usercontext = context_user::instance($user->id);
    $profilelink = '';
    if ($usercontext and has_capability('moodle/user:viewdetails', $usercontext) || has_coursecontact_role($user->id)) {
        $profilelink = $CFG->wwwroot . '/user/view.php?id=' . $user->id;
    }
    $output = $OUTPUT->box_start('user-box', 'user' . $user->id);
    $fullname = fullname($user);
    $alt = '';
    if (!empty($profilelink)) {
        $output .= '<a href="' . $profilelink . '">';
        $alt = $fullname;
    }
    $output .= $OUTPUT->user_picture($user, array('size' => 100));
    $output .= '<br />';
    if (!empty($profilelink)) {
        $output .= '</a>';
    }
    //truncate name if it's too big
    if (core_text::strlen($fullname) > 26) {
        $fullname = core_text::substr($fullname, 0, 26) . '...';
    }
    $output .= '<strong>' . $fullname . '</strong>';
    $output .= $OUTPUT->box_end();
    if ($return) {
        return $output;
    } else {
        echo $output;
    }
}
开发者ID:evltuma,项目名称:moodle,代码行数:41,代码来源:deprecatedlib.php

示例15: blog_sync_external_entries

/**
 * Given a record in the {blog_external} table, checks the blog's URL
 * for new entries not yet copied into Moodle.
 * Also attempts to identify and remove deleted blog entries
 *
 * @param object $externalblog
 * @return boolean False if the Feed is invalid
 */
function blog_sync_external_entries($externalblog)
{
    global $CFG, $DB;
    require_once $CFG->libdir . '/simplepie/moodle_simplepie.php';
    $rss = new moodle_simplepie();
    $rssfile = $rss->registry->create('File', array($externalblog->url));
    $filetest = $rss->registry->create('Locator', array($rssfile));
    if (!$filetest->is_feed($rssfile)) {
        $externalblog->failedlastsync = 1;
        $DB->update_record('blog_external', $externalblog);
        return false;
    } else {
        if (!empty($externalblog->failedlastsync)) {
            $externalblog->failedlastsync = 0;
            $DB->update_record('blog_external', $externalblog);
        }
    }
    $rss->set_feed_url($externalblog->url);
    $rss->init();
    if (empty($rss->data)) {
        return null;
    }
    //used to identify blog posts that have been deleted from the source feed
    $oldesttimestamp = null;
    $uniquehashes = array();
    foreach ($rss->get_items() as $entry) {
        // If filtertags are defined, use them to filter the entries by RSS category
        if (!empty($externalblog->filtertags)) {
            $containsfiltertag = false;
            $categories = $entry->get_categories();
            $filtertags = explode(',', $externalblog->filtertags);
            $filtertags = array_map('trim', $filtertags);
            $filtertags = array_map('strtolower', $filtertags);
            foreach ($categories as $category) {
                if (in_array(trim(strtolower($category->term)), $filtertags)) {
                    $containsfiltertag = true;
                }
            }
            if (!$containsfiltertag) {
                continue;
            }
        }
        $uniquehashes[] = $entry->get_permalink();
        $newentry = new stdClass();
        $newentry->userid = $externalblog->userid;
        $newentry->module = 'blog_external';
        $newentry->content = $externalblog->id;
        $newentry->uniquehash = $entry->get_permalink();
        $newentry->publishstate = 'site';
        $newentry->format = FORMAT_HTML;
        // Clean subject of html, just in case
        $newentry->subject = clean_param($entry->get_title(), PARAM_TEXT);
        // Observe 128 max chars in DB
        // TODO: +1 to raise this to 255
        if (core_text::strlen($newentry->subject) > 128) {
            $newentry->subject = core_text::substr($newentry->subject, 0, 125) . '...';
        }
        $newentry->summary = $entry->get_description();
        //used to decide whether to insert or update
        //uses enty permalink plus creation date if available
        $existingpostconditions = array('uniquehash' => $entry->get_permalink());
        //our DB doesnt allow null creation or modified timestamps so check the external blog supplied one
        $entrydate = $entry->get_date('U');
        if (!empty($entrydate)) {
            $existingpostconditions['created'] = $entrydate;
        }
        //the post ID or false if post not found in DB
        $postid = $DB->get_field('post', 'id', $existingpostconditions);
        $timestamp = null;
        if (empty($entrydate)) {
            $timestamp = time();
        } else {
            $timestamp = $entrydate;
        }
        //only set created if its a new post so we retain the original creation timestamp if the post is edited
        if ($postid === false) {
            $newentry->created = $timestamp;
        }
        $newentry->lastmodified = $timestamp;
        if (empty($oldesttimestamp) || $timestamp < $oldesttimestamp) {
            //found an older post
            $oldesttimestamp = $timestamp;
        }
        if (core_text::strlen($newentry->uniquehash) > 255) {
            // The URL for this item is too long for the field. Rather than add
            // the entry without the link we will skip straight over it.
            // RSS spec says recommended length 500, we use 255.
            debugging('External blog entry skipped because of oversized URL', DEBUG_DEVELOPER);
            continue;
        }
        if ($postid === false) {
            $id = $DB->insert_record('post', $newentry);
//.........这里部分代码省略.........
开发者ID:eamador,项目名称:moodle-course-custom-fields,代码行数:101,代码来源:lib.php


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