當前位置: 首頁>>代碼示例>>PHP>>正文


PHP Strings::trimLineBreaks方法代碼示例

本文整理匯總了PHP中Strings::trimLineBreaks方法的典型用法代碼示例。如果您正苦於以下問題:PHP Strings::trimLineBreaks方法的具體用法?PHP Strings::trimLineBreaks怎麽用?PHP Strings::trimLineBreaks使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在Strings的用法示例。


在下文中一共展示了Strings::trimLineBreaks方法的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: _readMsg

	protected function _readMsg($function = "_readMsg") {
		if(!$this->connected) {
			$this->pushError($function, 'Connect first');
			return false;
		}
		$result = true;
		$this->message = '';
		$this->code = 0;
		$go = true;
		do {
			$tmp = @socket_read($this->ftp_control_sock, 4096, PHP_BINARY_READ);
			if($tmp === false) {
				$go = false;
				$result = false;
				$socketErr = socket_strerror(socket_last_error($this->ftp_control_sock));
				$this->pushError($function, 'Read failed', $socketErr);
				$regs = array(0, 0);
			}
			else {
				$this->message .= $tmp;
				$go = !preg_match(
					"/^([0-9]{3})(-.+\\1)? [^".self::CRLF."]+".self::CRLF."$/Us",
					$this->message,
					$regs
				);
			}
		} while($go);
		if($this->LocalEcho) {
			echo "GET < ".Strings::trimLineBreaks($this->message).self::CRLF;
		}
		$this->code = (int) $regs[1];
		return $result;
	}
開發者ID:BackupTheBerlios,項目名稱:viscacha-svn,代碼行數:33,代碼來源:class.FTPClientSockets.php

示例2: _readMsg

	protected function _readMsg($function = "_readmsg") {
		if(!$this->connected) {
			$this->pushError($function, 'Connect first');
			return false;
		}
		if (!is_array($this->_ftp_data_sock)) {
			$this->pushError($function, 'No data retrieved');
			return false;
		}
		$result = true;
		$this->message = implode(self::CRLF, $this->ftp_data_sock).self::CRLF;
		$this->code = 0;
		$m = preg_match(
			"/^([0-9]{3})(-(.*[".self::CRLF."]{1,2})+\\1)? [^".self::CRLF."]+[".self::CRLF."]{1,2}$/m",
			$this->_message,
			$regs
		);
		if(!$m) {
			$this->pushError($function, 'Invalid response from FTP');
			return false;
		}
		if($this->LocalEcho) {
			echo "GET < ".Strings::trimLineBreaks($this->message).self::CRLF;
		}
		$this->code = (int) $regs[1];
		return $result;
	}
開發者ID:BackupTheBerlios,項目名稱:viscacha-svn,代碼行數:27,代碼來源:class.FTPClientExtension.php

示例3: read


//.........這裏部分代碼省略.........
	 *  if ($content !== false) {
	 *    echo $content;
	 *  }
	 * </code>
	 * <code>
	 *	$f = new File('core.log');
	 *	$content = $f->read(File::READ_LINES_FILLED);
	 *  if ($content !== false) {
	 *    print_r($content);
	 *  }
	 * </code>
	 *
	 * @param int Type to read the file, default: 0 (File::READ_STRING)
	 * @param int Mode to read a file: Unicode (default) or Binary
	 * @param string Only used when first parameter is > 0, contains partial content of the file.
	 * @return mixed Requested Content or false (or only the bool state when first param is > 0)
	 * @todo Check whether $fopenMode is really correct for php 6 binary/unicode handling
	 */
	public function read($type = File::READ_STRING, $mode = self::UNICODE, &$data = null) {
		if ($this->readable() == false) {
			return false;
		}

		if ($mode == self::BINARY) {
			$mode = FILE_BINARY;
			$fopenMode = 'rb';
		}
		else {
			$mode = FILE_TEXT;
			$fopenMode = 'r';
		}

		if ($type == self::READ_STRING) {
			$contents = file_get_contents($this->path, $mode);
			if ($contents !== false) {
				return $contents;
			}
			else {
				return false;
			}
		}
		elseif ($type == self::READ_LINES || $type == self::READ_LINES_FILLED) {
			// When filesize is > 8 MB we use another method to read the file into an array.
			if ($this->size() <= 8*1024*1024) {
				if ($type == self::READ_LINES_FILLED) {
					$flags = FILE_SKIP_EMPTY_LINES | $mode;
				}
				else {
					$flags = $mode;
				}
				$array = file($this->path, $flags);
			}
			else {
				$array = array();
				$this->handle = fopen($this->path, $fopenMode);
				if (is_resource($this->handle) == false) {
					return false;
				}
				while (feof($this->handle) == false) {
					$line = fgets($this->handle);
					$line = Strings::trimLineBreaks($line);
					if ($type == self::READ_LINES || !empty($line)) {
						$array[] = $line;
					}
				}
				fclose($this->handle);
			}
			// Remove line breaks
			$array = array_map(array('Strings', 'trimLineBreaks'), $array);
		}
		elseif ($type > 0) {
			if (is_resource($this->handle) == false) {
				$this->handle = fopen($this->path, $fopenMode);
				if (is_resource($this->handle) == false) {
					return false;
				}
			}
			if (feof($this->handle) == false) {
				$data = fread($this->handle, $type);
				if ($data !== false) {
					return true;
				}
				else {
					fclose($this->handle);
					return false;
				}
			}
			else {
				// Reached end of file (EOF)
				fclose($this->handle);
				return null;
			}
		}
		else {
			FileSystem::getDebug()->addText(
				"The specified type ({$type}) to read the file '{$this->path}' is not supported."
			);
			return false;
		}
	}
開發者ID:BackupTheBerlios,項目名稱:viscacha-svn,代碼行數:101,代碼來源:class.File.php

示例4: testTrimLineBreaks

	/**
	 * @dataProvider providerTrimLineBreaks
	 */
	public function testTrimLineBreaks($param1, $param2, $expected) {
		$result = Strings::trimLineBreaks($param1, $param2);
		$function = ($param2 == true) ? 'rtrim' : 'trim';
		$this->assertEquals($expected, $result, "Failed to {$function}: ".var_export($param1, true));
	}
開發者ID:BackupTheBerlios,項目名稱:viscacha-svn,代碼行數:8,代碼來源:StringsTest.php

示例5: _readMsg

	protected function _readMsg($function = "_readmsg") {
		if(!$this->connected) {
			$this->pushError($function, 'Connect first');
			return false;
		}
		$result = true;
		$this->message = '';
		$this->code = 0;
		$go = true;
		do {
			$tmp = @fgets($this->ftp_control_sock, 512);
			if($tmp === false) {
				$go = false;
				$result = false;
				$this->pushError($function, 'Read failed');
			}
			else {
				$this->message .= $tmp;
				$m = preg_match(
					"/^([0-9]{3})(-(.*[".self::CRLF."]{1,2})+\\1)? [^".self::CRLF."]+[".self::CRLF."]{1,2}$/",
					$this->message,
					$regs
				);
				if($m) {
					$go = false;
				}
			}
		} while($go);
		if($this->LocalEcho) {
			echo "GET < ".Strings::trimLineBreaks($this->message).self::CRLF;
		}
		$this->code = (int) $regs[1];
		return $result;
	}
開發者ID:BackupTheBerlios,項目名稱:viscacha-svn,代碼行數:34,代碼來源:class.FTPClientNative.php


注:本文中的Strings::trimLineBreaks方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。