Categories > OpenTBS with DOCX >

Carriage Returns instead of Line Breaks PHP/MySQL -> DocX

The forum is closed. Please use Stack Overflow for submitting new questions. Use tags: tinybutstrong , opentbs
By: JS
Date: 2015-03-05
Time: 00:08

Carriage Returns instead of Line Breaks PHP/MySQL -> DocX

Hi guys,

I'm hoping someone can help me out with this. I am having issues with a block of text (with paragraphs) entered via a text area in a web interface and stored in a MySQL DB being output with line breaks instead of carriage returns in the generated DOCX (I'm viewing in word 2010 and using a word template file). The MySQL syntax is currently using \r\n to separate paragraphs. What would be the appropriate separator to achieve a carriage return? Is there a "best" way to replace the current \r\n without altering it in the database?

I apologize in advance if there is an obvious answer to this.

Thank you.

Template:

[blk.title]

[author_blk;block=begin][author_blk.key][author_blk.val][author_blk;block=end]

[affiliation_blk;block=begin][affiliation_blk.val][affiliation_blk.key][affiliation_blk;block=end]

[blk.body]   <--- paragraphs currently separated by line breaks instead of carriage returns here

[blk.acknowledgements]
By: Skrol29
Date: 2015-03-05
Time: 17:24

Re: Carriage Returns instead of Line Breaks PHP/MySQL -> DocX

Hi,

OpenTBS supports many line breaks in the merged data such as "\r", "\n", "\r\n", and "\n\r".
They should already been replaced with DOCX line-breaks when merged.

You should check the actual binary content of the merged data.
By: JS
Date: 2015-03-06
Time: 03:07

Re: Carriage Returns instead of Line Breaks PHP/MySQL -> DocX

Thank you for the response Skrol. They are indeed being replaced with line breaks (shift + enter style) which is what I do not want. What would be the appropriate syntax to display a carriage return (just enter)? I've tried combinations of the above; however, they all seem to generate line breaks (shift + enter style).
By: Skrol29
Date: 2015-03-06
Time: 16:36

Re: Carriage Returns instead of Line Breaks PHP/MySQL -> DocX

OpenTBS replaces the ANSI line breaks with the entity <w:br/>. Wich is an actual valid line-break.

What you call a «  carriage return » seems the be a paragraph separator in Ms Word. This is not trully the same function than a line break. And most of all it is quite more complicated to
replace a simple line-break with a paragraph separator because of formating consideration.
By: JS
Date: 2015-03-06
Time: 17:52

Re: Carriage Returns instead of Line Breaks PHP/MySQL -> DocX

Yes I apologize, I seem to have confused my semantics. I meant line break to paragraph separator. Could you tell me what tag(s) are involved in accomplishing this?

Thank you again for all the help.
By: Skrol29
Date: 2015-03-08
Time: 00:02

Re: Carriage Returns instead of Line Breaks PHP/MySQL -> DocX

> Could you tell me what tag(s) are involved in accomplishing this?

A paragraph is defined by entity <w:p>.
So a very simply way, but quite risky, is to replace each ANSI line break with "</w:p><w:p>". This can be done using a custom function called by parameter "onformat".
But as I said, you'll probably met problems with the formating.
By: JS
Date: 2015-03-17
Time: 20:58

Re: Carriage Returns instead of Line Breaks PHP/MySQL -> DocX

I tried the following:

function f_paragraphs($FieldName, &$CurrVal) {
  $CurrVal= str_replace("\r\n", "</w:p><w:p>", $CurrVal);
}

It replaces \r\n however </w:p><w:p> is actually displayed as text rather than being recognized as tags.

This is the XML readout:

<w:p w:rsidR="00D77D7F" w:rsidRDefault="008D3E86" w:rsidP="00C20EED">
<w:pPr>
<w:jc w:val="both"/>
<w:rPr>
<w:color w:val="253340"/>
</w:rPr>
</w:pPr>
<w:r>
<w:rPr>
<w:color w:val="253340"/>
</w:rPr>
<w:t>
text goes here.</w:p><w:p></w:p><w:p></w:p><w:p>text goes here.</w:p><w:p></w:p><w:p></w:p><w:p>text goes here.
</w:t>
</w:r>
</w:p>

Any ideas?

Thank you.
By: Skrol29
Date: 2015-03-20
Time: 00:42

Re: Carriage Returns instead of Line Breaks PHP/MySQL -> DocX

Use parameter "strconv=no" in the TBS tags that display this data.
By: JS
Date: 2015-03-25
Time: 03:47

Re: Carriage Returns instead of Line Breaks PHP/MySQL -> DocX

Thank you very much Skrol29. It all worked out beautifully.
By: JS
Date: 2015-04-08
Time: 20:37

Re: Carriage Returns instead of Line Breaks PHP/MySQL -> DocX

One little glitch I just came across... It seems when the block text contains the less than sign "<" it breaks the XML and the document can no longer be opened. I am wondering if this is due to strconv=no and if there is anyway around this issue?
By: Skrol29
Date: 2015-04-09
Time: 00:51

Re: Carriage Returns instead of Line Breaks PHP/MySQL -> DocX

> when the block text contains the less than sign "<" it breaks the XML
> I am wondering if this is due to strconv=no

Yes of course, character "<" breaks the XML.

To avoid this, you can use « $CurrVal = htmlspecialchars($CurrVal);  » in f_paragraphs()
By: JS
Date: 2015-04-09
Time: 01:38

Re: Carriage Returns instead of Line Breaks PHP/MySQL -> DocX

That worked! Thank you again.