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


PHP Text::tokenize方法代码示例

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


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

示例1: remove

 /**
  * Remove data matching $path from the $data array.
  * You can use `{n}` and `{s}` to remove multiple elements
  * from $data.
  *
  * @param array $data The data to operate on
  * @param string $path A path expression to use to remove.
  * @return array The modified array.
  * @link http://book.cakephp.org/3.0/en/core--libraries/hash.html#Hash::remove
  */
 public static function remove(array $data, $path)
 {
     $noTokens = strpos($path, '[') === false;
     $noExpansion = strpos($path, '{') === false;
     if ($noExpansion && $noTokens && strpos($path, '.') === false) {
         unset($data[$path]);
         return $data;
     }
     $tokens = $noTokens ? explode('.', $path) : Text::tokenize($path, '.', '[', ']');
     if ($noExpansion && $noTokens) {
         return static::_simpleOp('remove', $data, $tokens);
     }
     $token = array_shift($tokens);
     $nextPath = implode('.', $tokens);
     list($token, $conditions) = self::_splitConditions($token);
     foreach ($data as $k => $v) {
         $match = static::_matchToken($k, $token);
         if ($match && is_array($v)) {
             if ($conditions && static::_matches($v, $conditions)) {
                 unset($data[$k]);
                 continue;
             }
             $data[$k] = static::remove($v, $nextPath);
             if (empty($data[$k])) {
                 unset($data[$k]);
             }
         } elseif ($match && empty($nextPath)) {
             unset($data[$k]);
         }
     }
     return $data;
 }
开发者ID:QueenCityCodeFactory,项目名称:cakephp,代码行数:42,代码来源:Hash.php

示例2: testTokenize

 /**
  * testTokenize method
  *
  * @return void
  */
 public function testTokenize()
 {
     $result = Text::tokenize('A,(short,boring test)');
     $expected = ['A', '(short,boring test)'];
     $this->assertEquals($expected, $result);
     $result = Text::tokenize('A,(short,more interesting( test)');
     $expected = ['A', '(short,more interesting( test)'];
     $this->assertEquals($expected, $result);
     $result = Text::tokenize('A,(short,very interesting( test))');
     $expected = ['A', '(short,very interesting( test))'];
     $this->assertEquals($expected, $result);
     $result = Text::tokenize('"single tag"', ' ', '"', '"');
     $expected = ['"single tag"'];
     $this->assertEquals($expected, $result);
     $result = Text::tokenize('tagA "single tag" tagB', ' ', '"', '"');
     $expected = ['tagA', '"single tag"', 'tagB'];
     $this->assertEquals($expected, $result);
 }
开发者ID:ringiait,项目名称:portal,代码行数:23,代码来源:TextTest.php

示例3: testTokenize

 /**
  * testTokenize method
  *
  * @return void
  */
 public function testTokenize()
 {
     $result = Text::tokenize('A,(short,boring test)');
     $expected = ['A', '(short,boring test)'];
     $this->assertEquals($expected, $result);
     $result = Text::tokenize('A,(short,more interesting( test)');
     $expected = ['A', '(short,more interesting( test)'];
     $this->assertEquals($expected, $result);
     $result = Text::tokenize('A,(short,very interesting( test))');
     $expected = ['A', '(short,very interesting( test))'];
     $this->assertEquals($expected, $result);
     $result = Text::tokenize('"single tag"', ' ', '"', '"');
     $expected = ['"single tag"'];
     $this->assertEquals($expected, $result);
     $result = Text::tokenize('tagA "single tag" tagB', ' ', '"', '"');
     $expected = ['tagA', '"single tag"', 'tagB'];
     $this->assertEquals($expected, $result);
     // Ideographic width space.
     $result = Text::tokenize("tagA \"single tag\" tagB", " ", '"', '"');
     $expected = ['tagA', '"single tag"', 'tagB'];
     $this->assertEquals($expected, $result);
 }
开发者ID:Slayug,项目名称:castor,代码行数:27,代码来源:TextTest.php

示例4: import

 public function import()
 {
     $submissionFile = '';
     $table = '';
     //get form data
     if ($this->request->is('post')) {
         $submissionFile = $this->request->data['submissionFile'];
         $table = $this->request->data['table'];
     }
     //process
     if ($this->request->is('post')) {
         if ($submissionFile == '') {
             $this->set('file_status', 'No file submitted, try again.');
         } elseif ($submissionFile) {
             //read in file data
             $file = new File($submissionFile['tmp_name']);
             $rawFileData = $file->read(true, 'r');
             $lineArr = $array = preg_split("/\r\n|\n|\r/", $rawFileData);
             //parse file data line by line for appropriate table
             $this->set('file_status', 'File submitted.');
             if ($table == 0) {
                 $ticketsTable = TableRegistry::get('Tickets');
                 foreach ($lineArr as $line) {
                     $dataFields = Text::tokenize($line);
                     $ticket = $ticketsTable->newEntity();
                     $ticket->id = $dataFields[0];
                     $ticket->theater_id = $dataFields[1];
                     $ticket->section_id = $dataFields[2];
                     $ticket->row_id = $dataFields[3];
                     $ticket->seat_id = $dataFields[4];
                     $ticket->status = $dataFields[5];
                     $ticket->customer_id = $dataFields[6];
                     $ticket->customer_name = $dataFields[7];
                     $ticket->ticket_number = $dataFields[8];
                     $ticket->performance_id = $dataFields[9];
                     $ticket->season_id = $dataFields[10];
                     $ticket->purchase_id = $dataFields[11];
                     $ticketsTable->save($ticket);
                 }
             } elseif ($table == 1) {
                 $staffAssignmentsTable = TableRegistry::get('StaffAssignments');
                 foreach ($lineArr as $line) {
                     $dataFields = Text::tokenize($line);
                     $staffAssignment = $staffAssignmentsTable->newEntity();
                     $staffAssignment->id = $dataFields[0];
                     $staffAssignment->user_id = $dataFields[1];
                     $staffAssignment->theater_id = $dataFields[2];
                     $staffAssignment->access_level = $dataFields[3];
                     $staffAssignmentsTable->save($staffAssignment);
                 }
             } elseif ($table == 2) {
                 $usersTable = TableRegistry::get('Users');
                 foreach ($lineArr as $line) {
                     $dataFields = Text::tokenize($line);
                     $user = $usersTable->newEntity();
                     $user->id = $dataFields[0];
                     $user->name = $dataFields[1];
                     $user->street = $dataFields[2];
                     $user->city = $dataFields[3];
                     $user->state = $dataFields[4];
                     $user->zip = $dataFields[5];
                     $user->phone_number = $dataFields[6];
                     $user->email = $dataFields[7];
                     $user->password = $dataFields[8];
                     $user->is_super_admin = $dataFields[9];
                     $user->date_created = $dataFields[10];
                     $user->date_modified = $dataFields[11];
                     $user->salt = $dataFields[12];
                     $usersTable->save($user);
                 }
             } elseif ($table == 3) {
                 $theatersTable = TableRegistry::get('Theaters');
                 foreach ($lineArr as $line) {
                     $dataFields = Text::tokenize($line);
                     $theater = $theatersTable->newEntity();
                     $theater->id = $dataFields[0];
                     $theater->name = $dataFields[1];
                     $theater->sales_tax = $dataFields[2];
                     $theater->description = $dataFields[3];
                     $theater->location = $dataFields[4];
                     $theater->artwork = $dataFields[5];
                     $theatersTable->save($theater);
                 }
             } elseif ($table == 4) {
                 $sectionsTable = TableRegistry::get('Sections');
                 foreach ($lineArr as $line) {
                     $dataFields = Text::tokenize($line);
                     $section = $sectionsTable->newEntity();
                     $section->id = $dataFields[0];
                     $section->name = $dataFields[1];
                     $section->code = $dataFields[2];
                     $section->theater_id = $dataFields[3];
                     $section->accessible_section = $dataFields[4];
                     $section->front_text = $dataFields[5];
                     $section->back_text = $dataFields[6];
                     $sectionsTable->save($section);
                 }
             } elseif ($table == 5) {
                 $seatsTable = TableRegistry::get('Seats');
                 foreach ($lineArr as $line) {
//.........这里部分代码省略.........
开发者ID:JesseDarellMoore,项目名称:CS499,代码行数:101,代码来源:SetupAdminController.php


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