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


PHP core_text::trim_utf8_bom方法代码示例

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


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

示例1: readdata

 /**
  * Return complete file within an array, one item per line
  * @param string filename name of file
  * @return mixed contents array or false on failure
  */
 protected function readdata($filename)
 {
     if (is_readable($filename)) {
         $filearray = file($filename);
         // If the first line of the file starts with a UTF-8 BOM, remove it.
         $filearray[0] = core_text::trim_utf8_bom($filearray[0]);
         // Check for Macintosh OS line returns (ie file on one line), and fix.
         if (preg_match("~\r~", $filearray[0]) and !preg_match("~\n~", $filearray[0])) {
             return explode("\r", $filearray[0]);
         } else {
             return $filearray;
         }
     }
     return false;
 }
开发者ID:covex-nn,项目名称:moodle,代码行数:20,代码来源:format.php

示例2: vmoodle_is_empty_line_or_format

/**
 * Check a CSV input line format for empty or commented lines
 * Ensures compatbility to UTF-8 BOM or unBOM formats
 */
function vmoodle_is_empty_line_or_format(&$text, $resetfirst = false)
{
    global $CFG;
    vmoodle_setup_local_config();
    static $first = true;
    // We may have a risk the BOM is present on first line.
    if ($resetfirst) {
        $first = true;
    }
    if ($first && $CFG->local_vmoodle_encoding == 'UTF-8') {
        $text = core_text::trim_utf8_bom($text);
        $first = false;
    }
    $text = preg_replace("/\n?\r?/", '', $text);
    if ($CFG->local_vmoodle_encoding != 'UTF-8') {
        $text = utf8_encode($text);
    }
    // last chance
    if ('ASCII' == mb_detect_encoding($text)) {
        $text = utf8_encode($text);
    }
    // Check the text is empty or comment line and answer true if it is
    return preg_match('/^$/', $text) || preg_match('/^(\\(|\\[|-|#|\\/| )/', $text);
}
开发者ID:OctaveBabel,项目名称:moodle-itop,代码行数:28,代码来源:clilib.php

示例3: test_trim_utf8_bom

 /**
  * Tests the static trim_utf8_bom method.
  */
 public function test_trim_utf8_bom()
 {
     $bom = "";
     $str = "Žluťoučký koníček";
     $this->assertSame($str . $bom, core_text::trim_utf8_bom($bom . $str . $bom));
 }
开发者ID:rushi963,项目名称:moodle,代码行数:9,代码来源:text_test.php

示例4: load_csv_content

 /**
  * Parse this content
  *
  * @global object
  * @global object
  * @param string $content passed by ref for memory reasons, unset after return
  * @param string $encoding content encoding
  * @param string $delimiter_name separator (comma, semicolon, colon, cfg)
  * @param string $column_validation name of function for columns validation, must have one param $columns
  * @param string $enclosure field wrapper. One character only.
  * @return bool false if error, count of data lines if ok; use get_error() to get error string
  */
 function load_csv_content(&$content, $encoding, $delimiter_name, $column_validation = null, $enclosure = '"')
 {
     global $USER, $CFG;
     $this->close();
     $this->_error = null;
     $content = core_text::convert($content, $encoding, 'utf-8');
     // remove Unicode BOM from first line
     $content = core_text::trim_utf8_bom($content);
     // Fix mac/dos newlines
     $content = preg_replace('!\\r\\n?!', "\n", $content);
     // Remove any spaces or new lines at the end of the file.
     if ($delimiter_name == 'tab') {
         // trim() by default removes tabs from the end of content which is undesirable in a tab separated file.
         $content = trim($content, chr(0x20) . chr(0xa) . chr(0xd) . chr(0x0) . chr(0xb));
     } else {
         $content = trim($content);
     }
     $csv_delimiter = csv_import_reader::get_delimiter($delimiter_name);
     // $csv_encode    = csv_import_reader::get_encoded_delimiter($delimiter_name);
     // Create a temporary file and store the csv file there,
     // do not try using fgetcsv() because there is nothing
     // to split rows properly - fgetcsv() itself can not do it.
     $tempfile = tempnam(make_temp_directory('/csvimport'), 'tmp');
     if (!($fp = fopen($tempfile, 'w+b'))) {
         $this->_error = get_string('cannotsavedata', 'error');
         @unlink($tempfile);
         return false;
     }
     fwrite($fp, $content);
     fseek($fp, 0);
     // Create an array to store the imported data for error checking.
     $columns = array();
     // str_getcsv doesn't iterate through the csv data properly. It has
     // problems with line returns.
     while ($fgetdata = fgetcsv($fp, 0, $csv_delimiter, $enclosure)) {
         // Check to see if we have an empty line.
         if (count($fgetdata) == 1) {
             if ($fgetdata[0] !== null) {
                 // The element has data. Add it to the array.
                 $columns[] = $fgetdata;
             }
         } else {
             $columns[] = $fgetdata;
         }
     }
     $col_count = 0;
     // process header - list of columns
     if (!isset($columns[0])) {
         $this->_error = get_string('csvemptyfile', 'error');
         fclose($fp);
         unlink($tempfile);
         return false;
     } else {
         $col_count = count($columns[0]);
     }
     // Column validation.
     if ($column_validation) {
         $result = $column_validation($columns[0]);
         if ($result !== true) {
             $this->_error = $result;
             fclose($fp);
             unlink($tempfile);
             return false;
         }
     }
     $this->_columns = $columns[0];
     // cached columns
     // check to make sure that the data columns match up with the headers.
     foreach ($columns as $rowdata) {
         if (count($rowdata) !== $col_count) {
             $this->_error = get_string('csvweirdcolumns', 'error');
             fclose($fp);
             unlink($tempfile);
             $this->cleanup();
             return false;
         }
     }
     $filename = $CFG->tempdir . '/csvimport/' . $this->_type . '/' . $USER->id . '/' . $this->_iid;
     $filepointer = fopen($filename, "w");
     // The information has been stored in csv format, as serialized data has issues
     // with special characters and line returns.
     $storedata = csv_export_writer::print_array($columns, ',', '"', true);
     fwrite($filepointer, $storedata);
     fclose($fp);
     unlink($tempfile);
     fclose($filepointer);
     $datacount = count($columns);
     return $datacount;
//.........这里部分代码省略.........
开发者ID:abhilash1994,项目名称:moodle,代码行数:101,代码来源:csvlib.class.php


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