简体   繁体   English

在干净的字符串函数之间添加空格

[英]adding white space between clean string functions

I've got the following code which outputs two different strings sent from a php contact form. 我有以下代码输出从php联系表单发送的两个不同的字符串。

$email_message .= "Module: ".clean_string($modcode_1_from)."\s".clean_string($modcode_2_from)."\r\n";

is meant to display module code 1 and module code 2. 用于显示模块代码1和模块代码2。

Currently looks likes this 目前看起来像这样

1001\\s2002 1001 \\ S2002

However i want it to look like: 但是我希望它看起来像:

1001 2002 1001 2002

So i added \\s to add white space between the strings but it does not do anything for me. 所以我添加\\ s来在字符串之间添加空格,但它对我没有任何作用。

use non-breaking space   使用不间断的空间  or you can use \\t to add a tab char. 或者你可以使用\\t来添加标签字符。 And the best one is just a space: 而最好的只是一个空间:

$email_message .= "Module: " . clean_string($modcode_1_from). " ". clean_string($modcode_2_from) . "\r\n";


$email_message .= "Module: " . clean_string($modcode_1_from) . "\t" . clean_string($modcode_2_from) . "\r\n";


$email_message .= "Module: " . clean_string($modcode_1_from) . " " . clean_string($modcode_2_from) . "\r\n";

You can use this: 你可以用这个:

$email_message .= "Module: ".clean_string($modcode_1_from)." ".clean_string($modcode_2_from)."\r\n";

What I did: I removed the \\s and put a space in its place. 我做了什么:我删除了\\s并在其位置放置了一个空格。

IMPORTANT NOTE: DO NOT USE " " 重要说明:请勿使用" " , it will echo/add   ,它会回显/添加  between 1001 and 2002 . 10012002之间。

Resulting in: 1001 2002 导致: 1001 2002

Therefore, replace \\s with an actual space using your spacebar. 因此,使用空格键将\\s替换为实际空格。

Footnote (other options): 脚注(其他选项):

If you wish to later use your data in Excel for example, you could use a comma , (CSV, comma seperated value) as the seperating character or a tab for a tab-seperated value \\t ie "\\t" , or a semi-colon ; 如果您希望在以后使用你的数据在Excel例如,你可以使用一个逗号, (CSV,逗号分隔值)作为分隔条件字符或制表符分隔的值选项卡\\t"\\t" ,或半-colon ; ie "; " . "; "

You may need/want to add a space after the comma; 您可能需要/想要在逗号后添加空格; ie ", " for use as a CSV. ", "用作CSV。

Example output of using a comma: 1001, 1002 . 使用逗号的示例输出: 1001, 1002

Can you try changing the \\s to 你能尝试将\\ s更改为

' '

and see if this works for you? 看看这对你有用吗?

尝试这个,

$email_message .= "Module: ".clean_string($modcode_1_from)." ".clean_string($modcode_2_from)."\r\n";

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM