在 php 中的 exec 中的 echo 中间添加新行
Adding new line in middle of echo inside exec in php
这是我向用户发送电子邮件的 exec 命令。我想通过在每个应用程序、配置和计数器类型之后添加换行符来重新格式化邮件正文。
这是有效但在一行中输出所有内容的代码:
exec('echo "Please find attached the query result for: App: '.$varApp.' Config: '.$varConfig.' Counter Type: '.$varCtrType.' Thanks!" | /bin/mail -s "Testing" -a '.$output[8].' '.$varEmail.' 2>&1', $output2 );
这是用户电子邮件正文中该命令的输出:
Please find attached the query result for: App: ABCDEF Config: GHIJK
Counter Type: LMNOP <br> Thanks!
我曾尝试使用
和 /r/n,但没有成功。我还尝试了添加引号和 /.
的不同组合
没有提供任何所需输出的代码。
exec('echo "Please find attached the query result for:'<br>' App: '.$varApp.' '<br>' Config: '.$varConfig.' <br> Counter Type: '.$varCtrType.' <br> Thanks!" | /bin/mail -s "Testing" -a '.$output[8].' '.$varEmail.' 2>&1', $output2 )
或
exec('echo "Please find attached the query result for:/r/n App: '.$varApp.' /r/n Config: '.$varConfig.' <br> Counter Type: '.$varCtrType.' <br> Thanks!" | /bin/mail -s "Testing" -a '.$output[8].' '.$varEmail.' 2>&1', $output2 );
我想我不知道如何在这个 echo 语句的中间添加 breaks/newline。
非常感谢这里的任何指导!
谢谢!
使用 printf
命令而不是 echo
,它处理格式字符串中的转义序列。
此外,换行符的转义序列是\n
,而不是/n
。你根本不需要 \r
。
exec('printf "Please find attached the query result for:\n App: %s \n Config: %s \n Counter Type: %s \n Thanks!" "' . $varApp . '" "' . $varConfig . '" "' . $varCtrType . '"| /bin/mail -s "Testing" -a '.$output[8].' '.$varEmail.' 2>&1', $output2 );
这是我向用户发送电子邮件的 exec 命令。我想通过在每个应用程序、配置和计数器类型之后添加换行符来重新格式化邮件正文。
这是有效但在一行中输出所有内容的代码:
exec('echo "Please find attached the query result for: App: '.$varApp.' Config: '.$varConfig.' Counter Type: '.$varCtrType.' Thanks!" | /bin/mail -s "Testing" -a '.$output[8].' '.$varEmail.' 2>&1', $output2 );
这是用户电子邮件正文中该命令的输出:
Please find attached the query result for: App: ABCDEF Config: GHIJK
Counter Type: LMNOP <br> Thanks!
我曾尝试使用
和 /r/n,但没有成功。我还尝试了添加引号和 /.
没有提供任何所需输出的代码。
exec('echo "Please find attached the query result for:'<br>' App: '.$varApp.' '<br>' Config: '.$varConfig.' <br> Counter Type: '.$varCtrType.' <br> Thanks!" | /bin/mail -s "Testing" -a '.$output[8].' '.$varEmail.' 2>&1', $output2 )
或
exec('echo "Please find attached the query result for:/r/n App: '.$varApp.' /r/n Config: '.$varConfig.' <br> Counter Type: '.$varCtrType.' <br> Thanks!" | /bin/mail -s "Testing" -a '.$output[8].' '.$varEmail.' 2>&1', $output2 );
我想我不知道如何在这个 echo 语句的中间添加 breaks/newline。 非常感谢这里的任何指导!
谢谢!
使用 printf
命令而不是 echo
,它处理格式字符串中的转义序列。
此外,换行符的转义序列是\n
,而不是/n
。你根本不需要 \r
。
exec('printf "Please find attached the query result for:\n App: %s \n Config: %s \n Counter Type: %s \n Thanks!" "' . $varApp . '" "' . $varConfig . '" "' . $varCtrType . '"| /bin/mail -s "Testing" -a '.$output[8].' '.$varEmail.' 2>&1', $output2 );