0

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?

1
  • Thanks, all. I marked the first reply as the answer. Commented Nov 13, 2013 at 4:15

3 Answers 3

1

Newlines are represented by "\n":

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

Sign up to request clarification or add additional context in comments.

1 Comment

I was using single quote and found out "\n" does not work in single quote. Just a note.
0
$post_content += "this is a test\n";
$post_content += "&nbsp";

Comments

0

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.