我有一个包含字符串的变量。 例如:
15/11/12 14:56:49 INFO jvm.JvmMetrics: Initializing JVM Metrics with processName=JobTracker, sessionId=
15/11/12 14:56:49 INFO mapreduce.JobSubmitter: Cleaning up the staging area file:/tmp/hadoop-pranay/mapred/staging/pranay1505087555/.staging/job_local1505087555_0001
15/11/12 14:56:49 ERROR tool.ImportTool: Encountered IOException running import job: java.io.FileNotFoundException: File does not exist: hdfs://127.0.0.1:54310/home/<some id>/sqoop-1.4.5.bin__hadoop-2.0.4-alpha/lib/avro-1.7.5.jar
at org.apache.hadoop.hdfs.DistributedFileSystem$18.doCall(DistributedFileSystem.java:1122)
at org.apache.hadoop.hdfs.DistributedFileSystem$18.doCall(DistributedFileSystem.java:1114)
at org.apache.hadoop.fs.FileSystemLinkResolver.resolve(FileSystemLinkResolver.java:81)
为了得到这种结果,我该怎么做?
$message =
'Dear User1,
Your record submitted has been disapproved by User.
Remarks:
Document No.:
Record Title: Test1
Record URL: http://myapp.dev/records?id=1
Sincerely,
Admin
Dear User1,
Your record submitted has been disapproved by User.
Remarks:
Document No.:
Record Title: Test2
Record URL: http://myapp.dev/records?id=2
Sincerely,
Admin';
我想我可以使用 Dear User1,
Your record submitted has been disapproved by User.
Remarks:
Document No.:
Record Title: Test1
Record URL: http://myapp.dev/records?id=1
Record Title: Test2
Record URL: http://myapp.dev/records?id=2
Sincerely,
Admin
?
请提及我错过或您想知道的事情。任何想法都会非常感激!
答案 0 :(得分:2)
使用nl2br()
获得所需的输出。
echo nl2br($message);
输出
Dear User1,
Your record submitted has been disapproved by User.
Remarks:
Document No.:
Record Title: Test1
Record URL: http://myapp.dev/records?id=1
Sincerely,
Admin
Dear User1,
Your record submitted has been disapproved by User.
Remarks:
Document No.:
Record Title: Test2
Record URL: http://myapp.dev/records?id=2
Sincerely,
Admin
请参阅demo
答案 1 :(得分:1)
function manipulate($text){
$texts = preg_split("/(Remarks:|Sincerely,|Document No.:)/",$text,-1, PREG_SPLIT_DELIM_CAPTURE);
$str = $texts[0];
$str .= "Remarks: \n\nDocument No.:";
for($x=0;$x<count($texts);$x++){
if($texts[$x]=='Document No.:'){
$str .= trim($texts[($x+1)],"\r\n");
}
}
$str.= "\n\nSincerely,\n\nAdmin";
return $str;
}
如果你使用这个作为html使用nl2br()
喜欢
nl2br(manipulate($message)); //where $message is your "Dear User1,...."
答案 2 :(得分:0)
我认为你需要在html页面中显示。 尝试过nl2br()?
我认为使用heredoc语法应该更好,例如:
$message = <<< EOT_MSG
'Dear User1,
...
....
EOT_MSG;
答案 3 :(得分:0)
我认为你可以使用类似this的东西,替代heredoc。
在这里你可以找到图书馆。 https://gist.github.com/fcamp/c4cb828cfb22bbe845cb