Reputation: 57286
How can I convert line breaks into codes? For instance,
$array = array(
'title' => 'abc',
'content' => 'a paragraph
line break
line break
'
);
I want to convert $array['content']
to
a paragraph\r\n\t\r\n\tline break\r\n\t\r\n\tline break\r\n\t\r\n\t
Upvotes: 0
Views: 263
Reputation: 10015
You can also try:
echo addcslashes($array['content'],"\n\r\t");
(If you intend to keep the line feeds as your original example).
Upvotes: 3
Reputation: 522597
Something along these lines?
$array['content'] = str_replace(array("\n", "\t"), array('\r\n', '\t'), $array['content']);
Upvotes: 0