Sam
Sam

Reputation: 2347

Correct way to add a newline into a php string so that it appears as so in a mysql database

I'm aware that PHP ignores enters/white spaces and the \n character doesn't work within a string, so how would one do this?

Upvotes: 0

Views: 78

Answers (1)

Ariel
Ariel

Reputation: 26783

Why do you think \n doesn't work within a string? It does work.

You can do:

"asd\nasd"

Or:

"asd
asd"

Both will work just fine.

However:

'asd\nasd'

has the actual characters \n not a newline, so check which quotes you are using.

But:

'asd
asd'

works fine.

Upvotes: 3

Related Questions