本文整理汇总了PHP中Strings::toArray方法的典型用法代码示例。如果您正苦于以下问题:PHP Strings::toArray方法的具体用法?PHP Strings::toArray怎么用?PHP Strings::toArray使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Strings
的用法示例。
在下文中一共展示了Strings::toArray方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: deserializeHeaders
public function deserializeHeaders($flat_headers) {
$tmp_headers = Strings::toArray($flat_headers);
if (preg_match("~HTTP/(\d\.\d)\s+(\d+).*~i", $tmp_headers[0], $matches) > 0) {
$this->setHeader('Protocol-Version', $matches[1]);
$this->setHeader('Status', $matches[2]);
}
array_shift($tmp_headers);
foreach($tmp_headers as $value) {
$pos = strpos($value, ':');
if ($pos !== false) {
$key = substr($value, 0, $pos);
$value = trim(substr($value, $pos+1));
if (strtolower($key) == 'set-cookie') {
$this->cookiesHeaders[] = $value;
}
else {
$this->setHeader($key, $value);
}
}
}
}
示例2: parseString
/**
* Parses a string containing csv formatted data.
*
* Returns a multidimensional array with the parsed content of the string or null on failure.
* If the usage of headers are enabled the header values are used as keys for the array.
*
* @param string String containing csv data.
* @return array Array with the data or null on failure
*/
public function parseString($str) {
if (!is_string($str)) {
return null;
}
$lines = Strings::toArray($str);
$data = array();
$header = array();
$numLine = ($this->headers == true) ? -1 : 0;
foreach($lines as $line) {
$cols = $this->parseLine($line);
if ($numLine >= 0) {
$data[$numLine] = array();
}
$numCol = 0;
foreach($cols as $col) {
if($numLine == -1 && $this->headers == true) {
$header[$numCol] = $col;
}
elseif($numLine >= 0 && $this->headers == true) {
$data[$numLine][$header[$numCol]] = $this->unescape($col);
}
else {
$data[$numLine][$numCol] = $this->unescape($col);
}
$numCol++;
}
$numLine++;
}
return $data;
}