سؤال

I use simplexml_load_file to open a soap envelope. When I get to one of the elements of the body, which contains plain text with new lines, and I want to display it, it's displayed without the new lines.

SOAP ENVELOPE extract:

[...]    
<Note>root@podio1:~# Aug 10 12:18:20 podio1 genunix: NOTICE: clcomm: Path podio1:nge1 - podio2:nge1 being drained
Aug 10 12:18:20 podio1 genunix: NOTICE: clcomm: Path podio1:e1000g1 - podio2:e1000g1 being drained
Aug 10 12:18:20 podio1 genunix: NOTICE: CMM: Node podio2 (nodeid = 2) is down.
Aug 10 12:18:20 podio1 genunix: NOTICE: CMM: Cluster members: podio1 podio3.
Aug 10 12:18:20 podio1 in.routed[925]: 8056 bytes of routing message left over
Aug 10 12:18:21 podio1 genunix: NOTICE: CMM: node reconfiguration #3 completed.</Note>
[...]

and when I echo the note:

[...]
$comment = $Note->Comment;
echo $comment;
[...]

this is what I get on my PHP Page:

root@podio1:~# Aug 10 12:18:20 podio1 genunix: NOTICE: clcomm: Path podio1:nge1 - podio2:nge1 being drained Aug 10 12:18:20 podio1 genunix: NOTICE: clcomm: Path podio1:e1000g1 - podio2:e1000g1 being drained Aug 10 12:18:20 podio1 genunix: NOTICE: CMM: Node podio2 (nodeid = 2) is down. Aug 10 12:18:20 podio1 genunix: NOTICE: CMM: Cluster members: podio1 podio3. Aug 10 12:18:20 podio1 in.routed[925]: 8056 bytes of routing message left over Aug 10 12:18:21 podio1 genunix: NOTICE: CMM: node reconfiguration #3 completed.

Does anybody know what I can do to be able to display the new lines? Each line ends with [CR][LF] in the XML file.

Thanks in advance,

Cristina

هل كانت مفيدة؟

المحلول

Newlines have no meaning in rendered HTML. To break to the next line you use <br> or <br /> so use:

echo nl2br($comment);

Or in cases where there is no newline:

echo "$comment<br />";

نصائح أخرى

You could capture the content in a variable first and then run:

$nolines = str_replace(array("\n", "\r"),'<br>', $var);
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top