简体   繁体   中英

HTML line break in PHP string?

In Wordpress editor, following code is kind of different to me:

case #1

this is a test 

case #2

this is a test
 

The first case will add a space after the sentence, and the #2 case will leave an empty line under the sentence.

Now I am writing a PHP that will include html code in a PHP string,

$post_content = "...."

How to distinguish the two cases above in this $post_content variable?

If I write

$post_content += "this is a test";
$post_content += "&nbsp";

It's the fist case, how to write the #2 case?

换行符用“ \\ n”表示:

$post_content += "this is a test\\n ";

$post_content += "this is a test\n";
$post_content += "&nbsp";

The difference is a newline. You denote it with \\n In PHP you do it like this

$str = "This is a string.\nThis is the second line.";

In your case

$post_content = "this is a test\n&nbsp";

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