Ok, I have search for about 3 hours and have decided to post this. I am pulling a XML feed and have one XML element that has a bunch of text creating one paragraph. When I look at the source though, I see it broken with carriage returns (as mentioned in the title, not sure if that’s correct).
Here is the feed I am pulling from: http://jobs.cbizsoft.com/cbizjobs/jobdetail_post.aspx?cid=cbiz_advantech&jobid=Req-0005
I am using php to build the xml file and then jquery/ajax to build the page as needed.
My question is if I can use php to parse the breaks and format the output to look nicer?
Thanks for the help!
Ok, if I understand you correctly, the problem is when the text is output in your HTML document, then the line breaks are gone. This is because in HTML line breaks (like all white space) is collapse into one space, so
and
produce the same output.
There are several ways you can solve this:
Put the CSS style
white-space: pre-line(orpre-wrap) on the surrounding element.Or use PHP to replace all line breaks with
<br>Or use a markdown library that basically does the same as the second point, but with additional kinds of formatting such as properly wrapping paragraphs or turn bullet lists in a real HTML list.