本文整理匯總了PHP中Strings::toTrimmedArray方法的典型用法代碼示例。如果您正苦於以下問題:PHP Strings::toTrimmedArray方法的具體用法?PHP Strings::toTrimmedArray怎麽用?PHP Strings::toTrimmedArray使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類Strings
的用法示例。
在下文中一共展示了Strings::toTrimmedArray方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: parseString
/**
* Parses a string containing INI formatted data.
*
* Returns an array with the parsed content of the string or null on failure.
* This function is case-sensitive when reading sections and keys.
*
* @param string String containing INI data.
* @return array Array with the data or null on failure
* @author Justin Frim <phpcoder@cyberpimp.pimpdomain.com>
*/
public function parseString($str) {
$array1 = Strings::toTrimmedArray($str);
$array2 = array();
// Reset comment etc.
$this->comment = array();
$section = '';
$firstElementFound = false;
foreach ($array1 as $line) {
if (empty($line) == true) {
// If line is empty jump to next line
continue;
}
// Read the first char of the line to analyse type (section, comment, element)
$firstchar = substr($line, 0, 1);
if ($firstchar == $this->commentChar) {
// It's a comment
if ($firstElementFound == false) {
// The comment belongs to the heading comment
$this->comment[] = trim(substr($line, 1));
}
}
else { // It's not a comment.
// We have found the first element (section or key/value).
// No more comments can be read, stop it...
$firstElementFound = true;
//It's an entry (not a comment and not a blank line)
if ($firstchar == '[' && substr($line, -1, 1) == ']') {
//It's a section
$section = substr($line, 1, -1);
}
else {
//It's a key...
$delimiter = strpos($line, '=');
if ($delimiter > 0) {
//...with a value
list($key, $value) = explode('=', $line, 2);
$key = trim($key);
$value = trim($value);
if (substr($value, 0, 1) == '"' && substr($value, -1, 1) == '"') {
$value = substr($value, 1, -1);
$value = str_replace('\\r', "\r", $value);
$value = str_replace('\\n', "\n", $value);
}
if ($this->mode == self::BINARY) {
$value = stripcslashes($value);
}
}
else {
//...without a value
$key = $line;
$value = '';
}
if (empty($section)) {
$array2[$key] = $value;
}
else {
$array2[$section][$key] = $value;
}
}
}
}
return $array2;
}
示例2: multiQuery
/**
* Performs one or more raw queries on the database.
*
* Executes one or multiple queries which are concatenated by a semicolon and a linebreak.
* You get back an array with all the results in the order of the queries.
* Comments are stripped.
*
* @param string Queries
*/
public function multiQuery($query) {
$results = array();
$lines = Strings::toTrimmedArray($query);
$query = '';
foreach ($lines as $line) {
$comment = substr($line, 0, 2);
if ($comment == '--' || $comment == '//' || strlen($line) <= 10) {
continue;
}
$query .= $line."\n";
}
$lines = explode(";\n", $query);
foreach ($lines as $key => $line) {
if (strlen($line) > 10) {
unset($result);
$result = $this->rawQuery($line);
$results[$key] = array();
if ($this->isResultSet($result) && $this->numRows($result) > 0) {
while ($row = $this->fetchAssoc($result)) {
$results[$key][] = $row;
}
}
}
}
return $s;
}