Luciano Nascimento
Luciano Nascimento

Reputation: 2600

CJSON::encode with New Line (\n)

Im trying to add a new line \n to CJSON::encode, but It's adding another \ that ignores the command. What should I do to CJSON::encode release \n?

Code:

CJSON::encode(array('error'=>'First Line\nSecond Line'))

Return:

{"error":"First Line\\nSecond Line"}

What I want:

{"error":"First Line\nSecond Line"}

Upvotes: 1

Views: 784

Answers (1)

soju
soju

Reputation: 25312

Well, not really a yii issue.

You simply cannot put new lines in a string using simple quotes :

http://php.net/manual/language.types.string.php#language.types.string.syntax.single

You should try :

CJSON::encode(array('error'=>"First Line\nSecond Line"))

Upvotes: 5

Related Questions