Tokenizes a string using $options['separator'], ignoring any instances of
$options['separator'] that appear between $options['leftBound'] and
$options['rightBound'].
public static tokenize ( string $data, array $options = [] ) : array | ||
$data | string | The data to tokenize. |
$options | array | Options to use when tokenizing: -`'separator'` _string_: The token to split the data on. -`'leftBound'` _string_: Left scope-enclosing boundary. -`'rightBound'` _string_: Right scope-enclosing boundary. |
return | array | Returns an array of tokens. |
/** * testTokenize method * * @return void */ public function testTokenize() { $result = String::tokenize('A,(short,boring test)'); $expected = array('A', '(short,boring test)'); $this->assertEqual($expected, $result); $result = String::tokenize('A,(short,more interesting( test)'); $expected = array('A', '(short,more interesting( test)'); $this->assertEqual($expected, $result); $result = String::tokenize('A,(short,very interesting( test))'); $expected = array('A', '(short,very interesting( test))'); $this->assertEqual($expected, $result); $result = String::tokenize('"single tag"', array('separator' => ' ', 'leftBound' => '"', 'rightBound' => '"')); $expected = array('"single tag"'); $this->assertEqual($expected, $result); $result = String::tokenize('tagA "single tag" tagB', array('separator' => ' ', 'leftBound' => '"', 'rightBound' => '"')); $expected = array('tagA', '"single tag"', 'tagB'); $this->assertEqual($expected, $result); $result = String::tokenize(array()); $expected = array(); $this->assertEqual($expected, $result); $result = String::tokenize(null); $this->assertNull($result); }