我对此进行了广泛搜索,但有没有办法忽略像' \ n'使用fwrite并将其打印在文件中?
$x = "Some data with \nslash n";
fwrite($fp, $x."\r\n");
Gives me :
Some data with
slash n
我知道使用单引号可以解决我的问题,但问题是$ x来自其他地方所以它的值已经设置好了。也许我错过了一些非常基本的东西。请帮忙
由于
答案 0 :(得分:0)
如果您只转义换行符,请将PHP_EOL常量附加到字符串,直接放在您想要换行符的位置。例如:
$x = "Some data with".PHP_EOL."slash n";
答案 1 :(得分:0)
我的答案很糟糕,但也许会有所帮助:
import UIKit
class RegisterPageViewController: UIViewController {
@IBOutlet weak var userFullNameTextField: UITextField!
@IBOutlet weak var userEmailTextField: UITextField!
@IBOutlet weak var userPasswordTextField: UITextField!
@IBOutlet weak var userRepeatPasswordTextField: UITextField!
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view.
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
@IBAction func RegisterButtonTapped(sender: AnyObject) {
let userFullName = userFullNameTextField.text
let userEmail = userEmailTextField.text
let userPassword = userPasswordTextField.text
let userRepeatPassword = userRepeatPasswordTextField.text
}
// Check for empty fields
**//ERROR HERE EXPECTED DECLARATION**
if (((userFullName.isEmpty || userEmail.isEmpty || userPassword.isEmpty || userRepeatPassword.isEmpty))
{
// Display alert message
displayMyAlertMessage("All fields are required")
return;
}
// Check if passwords match
if(userPassword != userRepeatPassword)
{
// Display alert message
displayMyAlertMessage("Passwords do not match")
return;
}
func displayAlertMessage(userMessage:string)
{
var myAlert = UIAlertController(title:"Alert", message: userMessage, preferredStyle: UIAlertControllerStyle.Alert);
}
}
// Store Data
// Display alert message with confirmation
/*
// MARK: - Navigation
// In a storyboard-based application, you will often want to do a little preparation before navigation
override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
// Get the new view controller using segue.destinationViewController.
// Pass the selected object to the new view controller.
}
*/
}
答案 2 :(得分:0)
诀窍是双引号和单引号
在str_replace中搜索时使用双引号,并在返回值时使用单引号
要将文件替换并下载到您的PC,请输入以下代码:
<?php
$a = "My Name\n is Ashwani";
$b = str_replace("\n",'\n',$a);
header('Content-disposition: attachment; filename=output.txt');
header('Content-type: text/plain');
echo "This is the original data:\n".$a;
echo "\n\n\nThis is the replaced data:\n".$b;
?>
要在服务器上使用输出和扩展名csv编写文件,请输入以下代码:
<?php
$a = "My Name\n is Ashwani";
$b = str_replace("\n",'\n',$a);
$h = fopen("output.csv","w");
fwrite($h,"This is the original data:\n".$a);
fwrite($h,"\n\n\nThis is the replaced data:\n".$b);
fclose($h);
?>
希望这有帮助