试图在从 php 脚本发送的 sms 消息上获取新行
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/3508695/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Trying to get new line on sms message sent from php script
提问by Matt
I've been trying to get a new line generated in my SMS message sent from a PHP script. I've used \r\n, <BR>and some hex codes. No matter what I do the message comes to my phone without line breaks.
我一直在尝试在从 PHP 脚本发送的 SMS 消息中生成新行。我用过\r\n,<BR>和一些十六进制代码。无论我做什么,消息都会在没有换行的情况下到达我的手机。
$body .= 'City:'.$venue.'\r\n'; //<- doesn't work
$body .= 'State:'.$state.'<br>'; //<- doesn't work
This is my header type...(complete header not included)
这是我的标题类型...(不包括完整的标题)
$headers = "MIME-Version: 1.0\r\n";
$headers .= "Content-type: text/html; charset=iso-8859-1\r\n";
I use mail to send...
我用邮件发送...
mail($somenumber,$subject,$body,$headers)
Everything works fine in the sense that I receive the message. I hope that I'm missing something, because this is driving me crazy.
从我收到消息的意义上说,一切正常。我希望我错过了一些东西,因为这让我发疯。
回答by Nasser Al-Wohaibi
Use: %0a, worked for me in Nokia and Android
使用:%0a,在诺基亚和Android为我工作
回答by anonymous
'\n'will print two characters: \and n
'\n'将打印两个字符:\和n
"\n"will print a line feed character (0x0A)
"\n"将打印一个换行符 (0x0A)
回答by Mahmoud Saleh
for me sometimes %0aworks and sometimes \nworks depends on the SMS gateway
对我来说有时%0a有效,有时\n有效取决于短信网关
回答by Javed
Had same problem, this works for me.
有同样的问题,这对我有用。
$text .= chr(10) . 'hello world'; But all other answer didn't when i tested.
$text .= chr(10) 。'你好,世界'; 但是当我测试时,所有其他答案都没有。
回答by waqas
Try "\n" instead of '\n';
尝试“\n”而不是“\n”;
Because in single quotes it take the character as it is.
因为在单引号中,它按原样使用字符。
Example:
例子:
echo nl2br('one \n two');//print: one \n two
echo nl2br("one \n two");//print: one <br> two
回答by user1960994
Use \r\nand then encode it using urlencode(). It worked on Android
使用\r\n,然后使用urlencode(). 它适用于Android
回答by Roger Gajraj
You have to understand how that message is encoded to be sent. For my situation, using routosms api, I had to disable their api's use of urlencode(using php) on my message string. Then, %0A worked.
您必须了解该消息是如何编码才能发送的。对于我的情况,使用 routosms api,我不得不禁用他们的 api 在我的消息字符串上使用 urlencode(使用 php)。然后,%0A 起作用了。
回答by user2034047
Use double quotes, single quotes don't recognize new lines
使用双引号,单引号不识别换行
回答by Matt
Just a little bit of code helps the medicine go down. I forgot an important little piece of code:
只需一点点代码就可以帮助药物下降。我忘记了一段重要的代码:
Content-Transfer-Encoding: 7bit
内容传输编码:7 位
You need the code above added to your header. HTH.
您需要将上面的代码添加到您的标题中。哈。
回答by Borealid
You are setting the content type as text/html. Try sending a <br/>. HTML is whitespace-agnostic and uses the break tag to force a new line.
您将内容类型设置为 text/html。尝试发送<br/>. HTML 与空格无关,并使用 break 标签强制换行。
If you don't want the message to be HTML, don't mark it as such.
如果您不希望消息为 HTML,请不要将其标记为 HTML。

