简体   繁体   中英

adding white space between clean string functions

I've got the following code which outputs two different strings sent from a php contact form.

$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.

Currently looks likes this

1001\\s2002

However i want it to look like:

1001 2002

So i added \\s to add white space between the strings but it does not do anything for me.

use non-breaking space   or you can use \\t to add a tab char. 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.

IMPORTANT NOTE: DO NOT USE " " , it will echo/add   between 1001 and 2002 .

Resulting in: 1001 2002

Therefore, replace \\s with an actual space using your spacebar.

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 ; ie "; " .

You may need/want to add a space after the comma; ie ", " for use as a CSV.

Example output of using a comma: 1001, 1002 .

Can you try changing the \\s to

' '

and see if this works for you?

尝试这个,

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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