<p>Completely untested, but you should be able to do use something like the <a href="https://github.com/victor-in/Craft-TwigPCRE" rel="nofollow">Craft-TwigPCRE</a> plugin and some variation of this code:</p>

<pre><code>{% set text = "&lt;p&gt;Some text&lt;/p&gt; tags as well as stuff like &lt;strong&gt;.|preg_replace('/\&lt;p\&gt;/', '') %}

{% set text = text|preg_replace('/\&lt;\/p\&gt;/', '\\n') %}
</code></pre>

<p><code>\n</code> is the Line Feed control character for Unix/OSX.</p>

CC BY-SA 3.0
2015-08-11T12:09:38.423Z
Many thanks Brad, I will take a look later this afternoon and let you know how I get on.
Pathfinder
CC BY-SA 3.0
2015-08-11T13:41:59.473Z
Okay, spent some time on this one and ran into several issues.

The feed I tested it on is here: https://flourish-uk.com/indeed2.xml

The issues are that without |raw the text comes in with the symbol codes instead, so &lt; etc instead of the actual <p> tags.

In addition, while the preg_replace works, it struggles when |raw is enabled - nothing appears!

Using preg_replace as a test, I can get it to display the text with the extra symbols - replace them - but \\n appears as just that \\n and not a new line.
Pathfinder
CC BY-SA 3.0
2015-08-11T13:52:55.150Z
Updated and simplified the XML for now, to show the issues.
Pathfinder
CC BY-SA 3.0
2015-08-10T18:32:00.973Z
2015-08-10T18:32:00.973Z
Brad Bell
<p>I am exporting some fields to an XML feed. There is a rich text field with typically 4 paragraphs in it.</p>

<p>The default export kicks out:</p>

<pre><code>&lt;p&gt;Some text&lt;/p&gt; tags as well as stuff like &lt;strong&gt;.
</code></pre>

<p>This is easy to remove with |striptags.</p>

<p>However, this results in text that doesn't have proper spacing and removes any intended carriage returns.</p>

<p>I can fix the spacing with a</p>

<pre><code>|replace(".", ". ")
</code></pre>

<p>But I'd rather have the the Paragraphs to still have carriage returns as intended. I know I can add in the right UTF-8 symbol, but I don't want this in the data, I just want the spacing and carriage returns as if it were a plain text field and not to have the UTF-8 symbols in the feed itself.</p>

<p><a href="http://www.fileformat.info/info/unicode/char/000D/index.htm" rel="nofollow">http://www.fileformat.info/info/unicode/char/000D/index.htm</a></p>

<p>Any help, much appreciated.</p>

<replace>
Can I convert rich text field to have plain text output - with carriage returns?
# Can I convert rich text field to have plain text output - with carriage returns?

(Asked by: username_0 on 2015-08-10)

I am exporting some fields to an XML feed. There is a rich text field with typically 4 paragraphs in it.
The default export kicks out:
Some text tags as well as stuff like .

This is easy to remove with |striptags.
However, this results in text that doesn't have proper spacing and removes any intended carriage returns.
I can fix the spacing with a
|replace(".", ". ")

But I'd rather have the the Paragraphs to still have carriage returns as intended. I know I can add in the right UTF-8 symbol, but I don't want this in the data, I just want the spacing and carriage returns as if it were a plain text field and not to have the UTF-8 symbols in the feed itself.
http://www.fileformat.info/info/unicode/char/000D/index.htm
Any help, much appreciated.

**Tags:** replace

---

## 1 answers

### Answer by username_1 on 2015-08-10. Score: 1

Completely untested, but you should be able to do use something like the Craft-TwigPCRE plugin and some variation of this code:
{% set text = "Some text tags as well as stuff like .|preg_replace('/\/', '') %}

{% set text = text|preg_replace('/\<\/p\>/', '\\n') %}

\n is the Line Feed control character for Unix/OSX.

> **Comments:**
> **username_0**: Many thanks Brad, I will take a look later this afternoon and let you know how I get on.  
> **username_0**: Okay, spent some time on this one and ran into several issues.  The feed I tested it on is here: https://flourish-uk.com/indeed2.xml  The issues are that without |raw the text comes in with the symbol codes instead, so &lt; etc instead of the actual <p> tags.  In addition, while the preg_replace works, it struggles when |raw is enabled - nothing appears!  Using preg_replace as a test, I can get it to display the text with the extra symbols - replace them - but \\n appears as just that \\n and not a new line.  
> **username_0**: Updated and simplified the XML for now, to show the issues.  

---

