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


PHP Strings::replaceLineBreaks方法代码示例

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


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

示例1: __toString

	/**
	 * Returns a detailed error message.
	 *
	 * The error message contains:
	 * 1. Error Number (only if greater than zero)
	 * 2. Error Message
	 * 3. File Name
	 * 4. Line Number of the file
	 * 5. Executed SQL Query (optional)
	 *
	 * @return string All error details as string
	 */
	public function __toString() {
		$error = parent::__toString();
		if (empty($this->query) == false) {
			$query = Strings::replaceLineBreaks($this->query, "\t");
			$error .= "\r\nQuery: {$query}";
		}
		return $error;
	}
开发者ID:BackupTheBerlios,项目名称:viscacha-svn,代码行数:20,代码来源:class.QueryException.php

示例2: testReplaceLineBreaks

	/**
	 * @dataProvider providerReplaceLineBreaks
	 */
	public function testReplaceLineBreaks($param_string, $param_replace, $expected) {
		$result = Strings::replaceLineBreaks($param_string, $param_replace);
		$this->assertEquals(
			$expected,
			$result,
			"Could not properly replace line breaks with ".var_export($param_replace, true).
				" in string ".var_export($param_string, true)
		);
	}
开发者ID:BackupTheBerlios,项目名称:viscacha-svn,代码行数:12,代码来源:StringsTest.php

示例3: transformArray

	/**
	 * Transforms a multidimensional array (like arrays returned by FileINI::parse()) to a string.
	 *
	 * This function writes sections and keys case sensitive. Invalid characters are converted to
	 * ASCII dash/hyphen (-). Values are always enclosed by double-quotes. All line breaks are
	 * translated to CRLF.
	 *
	 * You can specify a comment to prepend before the file. This would overwrite a comment that
	 * was read before from the file. For a single line comment you can just specify a string that
	 * will be used, for a multiline comment you have to put each line into an array element. The
	 * comment must not contain line breaks, but if there are any, they will be replaced with a
	 * white space. If you specify an empty array no comment will be written, if you specify null
	 * (default) the comment read from the file will be used (if any). The comment char specified
	 * before ( FileINI::setCommentChar() ) will be used.
	 *
	 * @param array The data to transform
	 * @param mixed Comment to prepend before the file
	 * @return string The transformed data as CSV
	 * @author Justin Frim <phpcoder@cyberpimp.pimpdomain.com>
	 */
	public function transformArray(array $array, $comment = null) {
		// Handle comment parameter
		if (is_array($comment)) {
			$this->comment = $comment;
		}
		elseif ($comment !== null && !is_array($comment)) {
			$this->comment = array($comment);
		}

		$data = '';
		// Transform comment and add to ini
		if (count($this->comment) > 0) {
			foreach ($this->comment as $comtext) {
				$data .= $this->commentChar . Strings::replaceLineBreaks($comtext, ' ') . self::CRLF;
			}
		}

		// Transform data and add to ini
		foreach ($array as $sections => $items) {
			//Write the section
			if (isset($section)) {
				$data .= self::CRLF;
			}
			if (is_array($items)) {
				// Remove invalid chars from section name (\0-\37 is octal notation for ascii chars)
				$section = preg_replace('/[\0-\37]|\177/', "-", $sections);
				$data .= "[{$section}]" . self::CRLF;
				foreach ($items as $keys => $values) {
					// Remove invalid chars from key name
					$key = preg_replace('/[\0-\37]|=|\177/', "-", $keys);
					// Replace comment char at the beginning
		  			if (substr($key, 0, 1) == $this->commentChar) {
		  				$key = '-'.substr($key, 1);
		  			}
			  		$values = str_replace("\r", '\r', $values);
			  		$values = str_replace("\n", '\n', $values);
					if ($this->mode == self::BINARY) {
						$value = addcslashes($values, '');
					}
					// Will be ' keyname = "value"\r\n' (without ')
		  			$data .= ' ' . $key . ' = "' . $value . '"' . self::CRLF;
				}
			}
			else {
				$key = preg_replace('/[\0-\37]|=|\177/', "-", $sections);
		  		if (substr($key, 0, 1) == $this->commentChar) {
		  			$key = '-'.substr($key, 1);
		  		}
		  		$items = str_replace("\r", '\r', $items);
		  		$items = str_replace("\n", '\n', $items);
				if ($this->mode == self::BINARY) {
					$value = addcslashes($items, '');
				}
				// Will be 'keyname = "value"\r\n' (without ')
		  		$data .= $key . ' = "' . $value . '"' . self::CRLF;
			}
	  	}
		return $data;
	}
开发者ID:BackupTheBerlios,项目名称:viscacha-svn,代码行数:79,代码来源:class.FileINI.php

示例4: _data_write_block

	protected function _data_write_block($mode, $block) {
		if($mode != self::BINARY) {
			$block = Strings::replaceLineBreaks($block, $this->eol_code[$this->OS_remote]);
		}
		do {
			if(($t = @socket_write($this->ftp_temp_sock, $block)) === false) {
				$socketErr =  socket_strerror(socket_last_error($this->ftp_temp_sock));
				$this->pushError("_data_write", "socket_write", $ocketErr);
				$this->_data_close();
				return false;
			}
			$block = substr($block, $t);
		} while(!empty($block));
		return true;
	}
开发者ID:BackupTheBerlios,项目名称:viscacha-svn,代码行数:15,代码来源:class.FTPClientSockets.php

示例5: FixEOL

	/**
	 * Changes every end of line from CR or LF to CRLF.
	 * @access private
	 * @return string
	 */
	private function FixEOL($str) {
		return Strings::replaceLineBreaks($str, $this->LE);
	}
开发者ID:BackupTheBerlios,项目名称:viscacha-svn,代码行数:8,代码来源:class.PHPMailer.php

示例6: getStructure

	/**
	 * Returns the create statement for creating the specified table.
	 *
	 * Set the second parameter to true to add "DROP TABLE IF EXISTS" statements before the
	 * create statement.
	 *
	 * After executing this method the MySQL option "SQL_QUOTE_SHOW_CREATE" is set to 1.
	 *
	 * @param string Name of the table
	 * @param boolean Add drop statements (default: false, no drop statements)
	 * @return string Create statement or null
	 */
	public function getStructure($table, $drop = false) {
		// Activate Quotes in sql names
		$this->rawQuery('SET SQL_QUOTE_SHOW_CREATE = 1');

		$table_data = '';
		if ($drop == true) {
			$table_data .= 'DROP TABLE IF EXISTS '.chr(96).$table.chr(96).';' ."\n";
		}
		$result = $this->rawQuery('SHOW CREATE TABLE '.chr(96).$table.chr(96));
		$show_results = $this->fetchNum($result);
		if (!$this->isResultSet($show_results)) {
			return false;
		}
		else {
			$table_data .= Strings::replaceLineBreaks($show_results[1], "\n").';';
			return trim($table_data);
		}
	}
开发者ID:BackupTheBerlios,项目名称:viscacha-svn,代码行数:30,代码来源:class.VendorMySQL.php

示例7: _data_write_block

	protected function _data_write_block($mode, $block) {
		if($mode != self::BINARY) {
			$block = Strings::replaceLineBreaks($block, $this->eol_code[$this->OS_remote]);
		}

		do {
			if(($t = @fwrite($this->ftp_data_sock, $block)) === false) {
				$this->pushError("_data_write", "Can't write to socket");
				return false;
			}
			$block = substr($block, $t);
		} while(!empty($block));

		return true;
	}
开发者ID:BackupTheBerlios,项目名称:viscacha-svn,代码行数:15,代码来源:class.FTPClientNative.php

示例8: addText

	/**
	 * Text to add to the logfile.
	 *
	 * Line breaks, carriage returns and tabs will be converted to a single space char.
	 *
	 * @param string Text to write to the logfile
	 */
	public function addText($text) {
		$text = str_replace("\t", " ", $text);
		$text = Strings::replaceLineBreaks($text, " ");
		$this->logs[] = '['.gmdate('r').'] '.$text;
	}
开发者ID:BackupTheBerlios,项目名称:viscacha-svn,代码行数:12,代码来源:class.Debug.php

示例9: Data

	/**
	 * Issues a data command and sends the msg_data to the server
	 * finializing the mail transaction. $msg_data is the message
	 * that is to be send with the headers. Each header needs to be
	 * on a single line followed by a <CRLF> with the message headers
	 * and the message body being seperated by and additional <CRLF>.
	 *
	 * Implements rfc 821: DATA <CRLF>
	 *
	 * SMTP CODE INTERMEDIATE: 354
	 *     [data]
	 *     <CRLF>.<CRLF>
	 *     SMTP CODE SUCCESS: 250
	 *     SMTP CODE FAILURE: 552,554,451,452
	 * SMTP CODE FAILURE: 451,554
	 * SMTP CODE ERROR  : 500,501,503,421
	 * @access public
	 * @return bool
	 */
	public function Data($msg_data) {
		$this->error = null; // so no confusion is caused

		if (!$this->connected()) {
			$this->error = array("error" => "Called Data() without being connected");
			return false;
		}

		fputs($this->smtp_conn, "DATA".$this->CRLF);

		$rply = $this->get_lines();
		$code = substr($rply, 0, 3);

		if ($this->do_debug >= 2) {
			echo "SMTP -> FROM SERVER:".$rply.$this->CRLF.'<br />';
		}

		if ($code != 354) {
			$this->error = array(
				"error" => "DATA command not accepted from server",
				"smtp_code" => $code,
				"smtp_msg" => substr($rply, 4)
			);
			if ($this->do_debug >= 1) {
				echo "SMTP -> ERROR: ".$this->error["error"].": ".$rply.$this->CRLF.'<br />';
			}
			return false;
		}

		/* the server is ready to accept data!
		 * according to rfc 821 we should not send more than 1000
		 * including the CRLF
		 * characters on a single line so we will break the data up
		 * into lines by \r and/or \n then if needed we will break
		 * each of those into smaller lines to fit within the limit.
		 * in addition we will be looking for lines that start with
		 * a period '.' and append and additional period '.' to that
		 * line. NOTE: this does not count towards limit.
		 */

		// normalize the line breaks so we know the explode works
		$msg_data = Strings::replaceLineBreaks($msg_data, "\n");
		$lines = explode("\n", $msg_data);

		/* we need to find a good way to determine is headers are
		 * in the msg_data or if it is a straight msg body
		 * currently I am assuming rfc 822 definitions of msg headers
		 * and if the first field of the first line (':' sperated)
		 * does not contain a space then it _should_ be a header
		 * and we can process all lines before a blank "" line as
		 * headers.
		 */

		$field = substr($lines[0], 0, strpos($lines[0], ":"));
		$in_headers = false;
		if (!empty($field) && !strstr($field, " ")) {
			$in_headers = true;
		}

		$max_line_length = 998; // used below; set here for ease in change

		while (list(, $line) = @each($lines)) {
			$lines_out = null;
			if ($line == "" && $in_headers) {
				$in_headers = false;
			}
			// ok we need to break this line up into several smaller lines
			while (strlen($line) > $max_line_length) {
				$pos = strrpos(substr($line, 0, $max_line_length), " ");

				// Patch to fix DOS attack
				if (!$pos) {
					$pos = $max_line_length - 1;
					$lines_out[] = substr($line, 0, $pos);
					$line = substr($line, $pos);
				}
				else {
					$lines_out[] = substr($line, 0, $pos);
					$line = substr($line, $pos + 1);
				}

//.........这里部分代码省略.........
开发者ID:BackupTheBerlios,项目名称:viscacha-svn,代码行数:101,代码来源:class.SMTP.php


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