I have a template in ExpressionEngine setup to act as a TXT export of weblog entry data. Since the dataset contains a lot of natural language punctuation (commas, apostrophes, spaces, line breaks, etc.), I am using pipes to act as the delimiter between custom fields.
What I’d like to do is remove all of the line breaks [that’s contained in the custom fields] and replace them with spaces, so the information from the rendered template has each result on a single line. For example:
Heading || Heading || Heading
Line 1 || Data || Data || Data
Line 2 || Data || Data || Data
Line 3 || Data || Data || Data
Line 4 || Data || Data || Data
Line 5 || Data || Data || Data
Much of the data often contains intermixed soft and hard returns (and other special characters pasted from Microsoft Word documents no less!), so the actual export looks more like:
Heading || Heading || Heading
Line 1 || Data || Data || Data
Line 2 || Data || Data
|| Data
Line 3 || Data || Data
|| Data
Line 4 || Data || Data || Data
Line 5 || Data || Data || Data
When using the Find & Replace Plus plugin, I can find one or more newlines with the following Regular Expression:
{exp:replace_plus find="\\n+" replace=" " regex="yes"}
What I’d like help with is determining the Regular Expression to remove all types of newlines and linebreaks (\r, \n, \r\n, soft returns, hard returns, etc) and allow a single line per result from the weblog entries loop.
Does anyone have experience using the Find & Replace Plus plugin to accomplish this?
Maybe Oliver Heine’s Strip Linebreaks plugin can help you?
Brilliant, thank you – the plugin worked perfectly for my needs.
Hi Laisvunas, I’d had trouble with Low’s find and replace plugin, so I thought I’d give this one a whirl. It’s not working at all! Here’s my code:
{exp:html_strip keep="strong,em,p,h2,ul,ol,li,a,div"}{exp:replace_plus find="<div class=QUOTEimagerightQUOTE.*?div>|<div class=QUOTEimagecenterQUOTE.*?div>|<div class=QUOTEimageleftQUOTE.*?div>" replace="" regex="yes" multiple="yes"}{article_body}{/exp:replace_plus}{/exp:html_strip}
What am I doing wrong?? Thank you!
Thank you! I changed my code to this:
{exp:replace_plus find="<div class=:QUOTE:articleside:QUOTE:.*?div>|<div class=:QUOTE:imageright:QUOTE:.*?div>|<div class=:QUOTE:imagecenter:QUOTE:.*?div>|<div class=:QUOTE:imageleft:QUOTE:.*?div>" regex="yes" multiple="yes"}{article_body}{/exp:replace_plus}
And it works…except, as you can see, I added an additional parameter including the “articleside” div. The plugin is replacing all of the divs except for this one. Is there a reason for this? You can see this in action here: http://uvamagazine.org/mobile/article/this_old_academical_village/
The “articleside” div surrounds the paragraphs starting with “Handyman’s Delight”
Hi,
you might need to escape quotes:
{exp:replace_plus find="<div class=\\:QUOTE:articleside\\:QUOTE:.*?div>|<div class=\\:QUOTE:imageright\\:QUOTE:.*?div>|<div class=\\:QUOTE:imagecenter\\:QUOTE:.*?div>|<div class=\\:QUOTE:imageleft\\:QUOTE:.*?div>" regex="yes" multiple="yes"}{article_body}{/exp:replace_plus}
In case your regex pattern gets complicated you would better to check if it works in some program such as RegexBuddy, or in pure PHP and only then use it as plugin’s parameter.
Is there a way to do a wildcard? I’m using this to strip out LG Replace tags in the meta description and it would be great if I could replace a number with a wildcard. Currently I’m specifying:
{exp:replace_plus find="'|:QUOTE:|:LD:media_1:RD:|:LD:media_2:RD:|:LD:media_3:RD:|:LD:media_4:RD:|
:LD:media_5:RD:|:LD:media_6:RD:|:LD:media_7:RD:|:LD:media_8:RD:"
so you see how a wildcard would be quite handy.
I’d like to find all occurrences of the titles of a weblog. Can I populate the find parameter via an embedded template (or some other method) that creates a string something like “title1|title2|title3|title4″?
I tried, but didn’t have any luck.
I’m pondering ways to build an illustrated glossary that is easy for the client to maintain and whose terms can be automatically converted to links in any body of text.
Any advice would be appreciated.
Can I populate the find parameter via an embedded template (or some other method) that creates a string something like “title1|title2|title3|title4″?
You cannot populate parameter via an embedded template because embedded template is pased after the main template.
To create the string like “title1|title2|title3|title4″ the plugin Value Aggregator might be helpful.
Hi Laisvunas,
Thanks, but Value Aggregator doesn’t seem to be applicable my case. I would like to find all the text that occurs in several custom fields of one weblog that match the titles of a second weblog.
I tried Fresh Variables but that didn’t seem to work. Making a Fresh Variable to create the list of titles of the second weblog (title1|title2|title3|title4|…) was no problem (I used the query module to create the list of 150 titles). But I couldn’t get the fresh variable to work as a find parameter in a single-entry template for the first weblog:
{exp:replace_plus find="{myFreshVariable}”}
Is this still an issue of parsing order? or maybe my implementation? Any suggestions?
Thanks again.
Hi,
I’m using your other plugin Entry Categories with the following code
{exp:entry_cats entry_id="{entry_id}" backspace="2"}
<a href="http://{path=home/C/}">{level1_category0_cat_name}</a> >
{/exp:entry_cats}
Which will output a list of subcategories with > separating them. However On the last category I don’t want the > to be there - how would I remove only the last instance here? Basically I’m looking to replicate the backspace parameter. Thank you for your time.
Packet Tide owns and develops ExpressionEngine. © Packet Tide, All Rights Reserved.