EE: Find and Replace plugin
My first plugin for EE: Find & Replace. This post now provides a place for support for the Low Replace plugin.
Download and docs for Low Replace can be found in the Software section
My first plugin for EE: Find & Replace. This post now provides a place for support for the Low Replace plugin.
Download and docs for Low Replace can be found in the Software section
Comments
Praat jij nou maar Nederlands.
@Joost: ‘t Is voor een internationaal publiek bedoeld, vandaar.
Achzo :-)
Nice plugin, should come in handy somewhere.
@joost: pipe down, laddy!
NIce plugin, just one question
how to resplace [’ ] ?
for example i have “Parkinson’s Disease” no to resplace with “Heart Disease”
how can i do it ?
Alexo, you should probably make sure whether the single quote is converted to a html entity. Check the source code for this. You should probably use something like:
{exp:replace find="Parkinson’s" replace="Heart"}Hello there
Thank you Low for this piece of code : ’ :-)
Hi Low,
I use your plug-in on my site. It removes the tags and control characters in the Summary field so I can use it in the Descriptions meta tag.
Thanks a lot for the regular expressions support.
Magnus
I wasn’t able to get it to replace hard carriage returns with a space.
Using:
{exp:replace find=”(\\w)+
(\\w+)” replace=”$1SPACE$2″ regex=”yes” multiple=”yes”}
{/exp:replace}
It found the hard returns but didn’t insert the space in the replace.
i.e., with the text
“Get rid of the hard return
in this entry. And every other
hard return too.”
Result:
“Get rid of the hard returnin this entry. And every otherhard return too.”
And also the “find” would inexplicably skip some of the hard returns. But I’d be happy with getting the “replace” syntax right.
John,
i guess you could try working with the control characters directly instead, i.e.
find=”/(\\r\\n|\\r|\\n)/” replace=”/SPACE/”
(The above would support both the Windows, Macintosh and Unix end-of-line sequences; I don’t know if you need that but why not make it bullet-proof.)
Multiple=”yes” means nothing with a regex so you can leave it out. The plug-in always replaces all strings that match your regex.
Magnus
Hey Magnus,
Thanks for your post.
Your suggested control characters method seems to work in the same hit-and-miss way as mine. The “\w+” pattern seems to skip words beginning with capital letters. Is this normal? And the hard carriage returns that are getting removed aren’t getting replaced with a space. And you were also right about not needing Multiple=”yes” in a regex.
Here’s the pattern I used:
{exp:replace find=”/(\\w+)\\r(\\w+)/” replace=”/$1SPACE$2/” regex=”yes”}
Just curious: Why do you have a slash character after each open quote and before each close quote?
John
John, I got this working with the following pattern:
{exp:replace find="(\\r\\n|\\r|\\n)" replace="SPACE" regex="yes"}But, are you sure that this is what you want? Maybe there’s formatting being applied to your text, so that carriage returns are being converted to
<br />’s, which are left alone by the plugin. Do you have a working example online you can link to?Hello Low,
Your solution works about the same as mine or Magnus’. That is, it catches some of the line breaks/hard returns and misses others and fails to replace any that it finds with a space.
What I’m doing is using the Moblog module to turn e-mails into entries. The e-mailed entries come with a few bad high-ASCII characters and many line breaks/hard returns that I’m trying to remove by running them through some regiex-capable filter such as yours. The first thing I’d like to do is get rid of the line breaks, then maybe worry about some of the odd characters.
In my template, the field that I’m running through your filter has the Xhtml formatting option, but it doesn’t seem to make a difference if it’s on or off.
Thanks in advance for any help you can offer!
John, can you try this one?
{exp:replace find="\\s+" replace="SPACE" regex="yes"}That should replace any whitespace with one space. Also, if you can copy and paste your target text, you can try several regular expressions in this useful workbench.
John,
The slashes I use are just the normal regex delimiters, the same way you surround strings with quotes. You don’t need to use them since Low’s plugin neatly adds them for you if they’re missing. Sorry for any confusion.
You have a complex data-related problem that may be beyond what can be expected of a simple find/replace utility. It would be fairly easy to build a “cleanser” plug-in for EE to do what you want.
Otherwise, my next suggestion is that you simply reverse the pattern - have find/replace look for anything that isn’t in the allowed character set, and make that a space:
find=”/[^\\w]/” replace=”SPACE”
Just add all remaining characters you want to allow inside the square brackets. As usual, some special characters need to be prefixed by a backslash.
Hey Low, Trying to use your find and replace plugin to convert lastname, firstname into firstname lastname.
The first code I used was
find=”(\\w+), (\\w+)” replace=”\\2 \\1″ regex=”yes”
Which appears to work with singles names, ie “Joiners, The” gets replaced with “The Joiners”
However “Educated Animals, The” gets replaced with “Educated The Animals” (it should be “The Educated Animals”)
I was under the impression that the + would find one or more. so I thought it would find one or more words before the ,
I then tried (.+), to see if matching any character many times would work. It didn’t it gave the same result as above.
Using the reWork site you linked above the (.+), did link the first two words into a group the (\w+), didn’t.
Any ideas what I’m doing wrong?
Scrap that. The (.+) does work. I was changing the wrong instance of it to test. Doh!
Thanks for the excellent plugin.
Aha. You thought I’d let you off then didn’t you. Well unfortunately not.
Using (.+), (\w+) for some reason converts “¡Forward Russia!” into “Russia ¡Forward!”
(If ¡ doesn’t convert its a Inverted Exclamation Mark)
The reWork site and other regex utilities leave it alone. Am I doing something wrong or have I found a bug?
Hi David. Try this on for size:
find="([^,]+), (\\w+)" replace="$2 $1"That will look for anything but the comma in the first part. I think that should work.
Nope. Gives the same result. There’s no comma in this string so I’m confused as to why its matching it ¡Forward Russia! is correct and should be ignored by find and replace
Strange. It works here. Can you point me to your example? Send me an email if it’s private.
Strange very strange. My Example You’ll have to login first. Its still closed Dev and if you want to look at the template its v4/numbers_inc
Thanks in advance. I’ve probably done something stupid but I can’t see it
David, I don’t seem to be able to access the v4 template group in your control panel. But I tested this code, which seemed to work:
{exp:replace find="([^,]+), (.+)" replace="$2 $1" regex="yes"}{title}{/exp:replace}Note that I don’t use \w for the last part either. That’ll sort “Harvey, P.J.” out.
Ok. Very strange. The new regex fixes PJ Harvey (I hadn’t gotten around to spotting her yet) but forward Russia still doesn’t behave itself. I now get Russia! ¡Forward
Huh, what’s going on?
I created the v4 group after I created your member group. I’ve know fixed it so you can access it.
I spotted it! You’ve actually got two Forward Russia entries in your bands section: “¡Forward, Russia!” and “Forward Russia!”. There’s your problem, right there. :)
hmmm. Well I deleted Forward Russia! and still get Russia! ¡Forward. Can I assume the special character is breaking something?
OK I don’t know what I did but its now working. I was just testing it out on a different bit of the page and it now works.
Thanks for looking into this buddy.
It works now, ’cause I removed the comma from the title, which was “¡Forward, Russia!” (sic). Note the comma in the middle. There’s the culprit. :)
*bleep* I never noticed that. You my friend are a genius.
Help me please.
I have an image tag:
/images/uploads/image/expressionengine.png
and I need to get this:
http://linka.ws/phpThumb/phpThumb.php?src=/images/uploads/image/expressionengine.png&w=300
I’ve spend several hours trying understand regular expressions but it doesn’t helped… I’m not able to write this expression
Hey Xacret. You don’t really need to use regex to do this.
Say the only bit of the url that changes is the filename all you need to do is
FIND /images/
REPLACE phpThumb/phpThumb.php?src/images/
That will leave the rest of your link unchanged but give you the phpthumb bit too.
Yes, I did it with simple search and replace.
The link in my first comment was parsed.
I too have to add a parameter to the end of src: &w=300
I have an image tag:
/images/uploads/image/expressionengine.png
and I need to get this:
phpThumb.src=”/images/uploads/image/expressionengine.png&w=300″
Hi,
Does it work with custom fields? I’m trying to use it to replace a SPACE with a “+” in a Technorati tag that I’ve implemented as a custom field.
Like this:
{exp:replace find=”SPACE” replace=”+”}{Technorati-1}{/exp:replace}
I.e., I enter something like “Word Word” as the tag, and need to replace the space with a plus sign so the link itself actually contains “word+word”.
Thanks.
Oops. It was my mistake. Works just fine. Apologies.
Is there a way to capitalise using this plugin?
I have this:
{exp:replace find=”(\\w+)-(\\w+)” replace=”\\1SPACE/SPACE\\2″ regex=”yes”}{segment_2}{/exp:replace}
Which turns this:
“climate-change”
Into this:
“climate change”
I would also like to capitalise the first letter of every word, so I can get:
“Climate Change”
Is this possible? Thanks very much!
Adam, you can use CSS to do just that:
text-transform:capitalize;Thanks Low!
Unfortunately I need to use this in the <title>, so CSS won’t work.
Hi, would it be possible to put in multiple regular expressions and then say multiple=”yes”?
Something like this:
{exp:replace find=”regex1|regex2|regex3″ replace=”X” multiple=”yes”}
text you want processed
{/exp:replace}
I’m using the plugin to filter out some of the crap TinyMCE injects into its HTML…
Thank you for this plugin. Just used it a project. Very handy and it made me finally to start learning RegEx.
I’d like to use this on an email addresses:
first.last@website.com
so that it shows it like this: first last
Essentially, replaces the dot with a space (I know this is possible) and then takes the @ and everything after that and replaces it with nothing. I know the first is easy. Second possible?
Just fyi - the above post left out my email example. I basically want to take any email address and take out everything at the @ symbol and past it.
Also, if there are dots in the first part to replace with a space which I know is possible.
Yeah good day: i was just trying out some things and noticed that when you use:
{exp:replace find="[br]" replace="<BR>"}something [br] more thing
{/exp:replace}
This does not work, any ideas is the [ ] is causing the problem ?
Victor, the [] shouldn’t be a problem. Are you using any other plugins in combination with this one?
Thanks, all, for a lively and helpful discussion?
To anybody who (like Magnus) is using this plugin to convert a custom field to the META description tag: Care to share your code, including the list of “find”s? I’m wondering how to catch all entities, special characters and HTML, without continually updating my templates as users discover new problems to throw at me.
If you prefer to post your answer in the EE forums, clicking on my name will take you into the EE forum thread where I posted this question. If you post here, please let me know if you DON’T want me to cross-post it there.
Thanks in advance!
Hi Quena,
Whatever I can contribute to solve your problem I added to your thread in the EE forums.
Good luck!
Hiya,
Just wanted to say thanks for this plugin. I actually downloaded it yonks ago but came to using it today on something and realised that I hadn’t said thank you so here goes…
… Thank you!!
Keep up all the great work, it is very much appreciated.
Best wishes,
Mark
Hi, nice plugin. I trued this and work fine for me. Thanks and keep up good work mate.
Hey Low, the replace plugin is a given on any EE installation I work on, so thanks for releasing it :)
Just one random question - is there any way to replace a pipe | in a chunk of text? It’s not hugely important but I’m working with aggregated blog headlines that are something like:
Some blog title | Blog Posts | My Cool Blog
… which are fine for titles, but they look pretty ugly in my design, so I wouldn’t mind tweaking them a bit ;) If you have any suggestions it would be much appreciated, thanks!
@Luke Stevens: if you’re not using
multiple="yes"orregex="yes", then replacing a pipe should work just as any other character.Oh great, thanks for letting me know :)
Hi Low,
I have been trying every possible combination of things to make this work. I am using your plugin in ee with a blog posting audio files from hipcast. Hipcast sends this:
<iframe src=”http://www.hipcast.com/playweb?audioid=P85964305c5f19f6fd2df7dffdf1b1c73bFB+RFREYmN2&buffer=5&fc=FFFFFF&pc=CCFF33&kc=FFCC33&bc=FFFFFF&brand=1&player=ap21″ height=”20″ width=”246″ frameborder=”0″ scrolling=”no”> </iframe>
Essentially i need to convert out the opening and closing carots and my most recent attempt i tried the following
{exp:replace find=“<iframe;|scrolling=’no’>|</iframe>â€? replace=“<iframe|scrolling=’o'>|</iframe>â€? multiple=”yes”}
I also tried just replacing using <| >
Can you point me in the right direction?
@MS: I’m sorry, but I don’t understand what it is you’re trying to accomplish. Do you need to replace the opening and closing html-brackets with html-entities? In that case, you’d probably need something like
find="<|>" replace="<|>" multiple="yes".I am so sorry i didnt check that post carefully after submit
this is what hipcast sends
<br / >
& l t ;iframe src=”http://www.hipcast.com/playweb?audioid=P85964305c5f19f6fd2df7dffdf1b1c73bFB+RFREYmN2&buffer=5&fc=FFFFFF&pc=CCFF33&kc=FFCC33&bc=FFFFFF&brand=1&player=ap21″ height=”20″ width=”246″ frameborder=”0″ scrolling=”no” & g t; & l t ;/ iframe & g t ;
i added spaces so it wouldn’t convert.
This is the code (one of many attempts) I used (again spaces added)
{exp:replace find=“& l t ;| & g t ;â€? replace=“<|>â€? multiple=”yes”}
Low said above: “@Luke Stevens: if you’re not using multiple=”yes” or regex=”yes”, then replacing a pipe should work just as any other character.”
What if you need to replace a pipe character and use multiple=”yes”?
@Ian: with the current version (1.3), you can’t. I’ll need to update plugin to allow for such a functionality.
Works great :) but it doesn’t render out when inside the magpie plugin…
{exp:magpie url=”http://www.google.com?search={exp:replace find=”SPACE” replace=”+;”}{title}{/exp:replace}” limit=”1″ refresh=”720″}
any ideas?
@rh2600: you can’t use a plugin as input for another plugin like that. You’ll have to find a way to do the replacing before you use it as a parameter. By using php on input, for example.
Thanks a lot for great plugin. A trully time-saver!
First of all, thanks for this great plugin. It helped me with a big problem I had with paths for a site’s mobile version.
I think it’s necessary to escape any “/” in the regular expressions, and I didn’t see that in the documentation.
Hi,
thank you for this cool plugin. One question though: How do I replace a ” with nothing? I tried to escape it as \” but it didn´t work.
I checked the thread in the EE forum, but couldn´t find anything.
Thanks
awa
Hey awa. Try this:
{exp:replace find="QUOTE"} ... {/exp:replace}Dank u wel! That was a quick reply all is working now
awa
Hi! Picture this. Simply text like “drums guitar piano” needs to be replaced with drums guitar piano.. So the word has to replaced with a hyperlink that forms a filename based on it’s orgin name.
{exp:replace find=”\\w+” replace=”<a href=”[(the value of \w+]+.mp3″> [(the value of \w+]</a>” regex=”yes”}
drums guitar piano
{/exp:replace}
How far I am off? Kind regards, D’R
Hi Daemon. That’ll be something like
find="(\\w+)" replace="<a href='$1.mp3'>$1</a>" regex="yes", so you’re not far off.I have to replace as below and it works only few occurances, So correct me if this is wrong of the doing it.
exp:replace find=”’|–|â€Â?|“|Â|â€â€?|…” replace=”‘|-|QUOTE|QUOTE|SPACE|SPACE-” multiple =”yes”}{body}{/exp:replace}
Thanks,
VishnuP
VishnuP, check the html source — you might need to look for html entities instead of the special characters.
This is great! I have one question..
Is there any way to pass in an EE tag variable? I need to replace a certain word with a weblog field URL.
Peter
Screw my above question, it seems to work. Another question:
Can you parse multiple regexs with multiple outputs?
Peter
Worked great. Real time saver.
I’m doing a find a replace on the word “and” and replacing it with “&” but sometimes it picks the “and” from the middle of a word. Is there a way to ensure if only replaces “and” if there is a space before and after it so some words like “Expand” don’t look like “Exp&” afteward?
Is it possible to put the text I have modified into a variable?
I want to modify a string and then place its new value into a EE variable so i can use it throughout the webpage.
Please let me know.
Rob q: You’d have to use a regular expression, I guess.
Robbie: No, that’s not possible with this plugin.
Any chance you feel like adding a new parameter called var ? This way I could do my search and replace and then whatever I put in the var parameter would be the name of the variable the modified text gets placed into.
I’m not sure how difficult that would be to program…
Robbie: I’ll put in on a list somewhere, but don’t hold your breath. :)
ok, i won’t hold my breath but it will be very cool feature and the first of its kind. None of the search and replace string modifiers for EE do that. It would be one step closer to not having to use PHP at all in my page and that I think would be great.
Robbie, can you give me an example of how it should work? Cause at the moment, I cannot get a clear idea of what you want. You want “the text you have modified” in a variable. As far as I can tell, this could mean several things.
1. Not using regex, you want whatever you put in the
findparameter as a variable. In the first example, that variable would hold the value ‘you’. This is the text you have modified, but since you already need that value for the plugin, making it a variable seems pointless. You could use dynamically assigned variables for that.2. Using regex, you want whatever matches the pattern in the
findparameter as a variable. This isn’t possible, because, like in example #6, it can be several things.3. You want the full original text (everything between the tag pair before replacing) as a variable. But this will cause recursion problems, as you need to use the variable inside the tag pair as well.
Certainly.
Here is what i would like it do…I don’t remember your exact syntax so I’ll just sort sketch out the steps in plain english.
I have a string. my goal is modify the string. Say I want to use ltrim to remove the http://www.flickr.com/1298234230/ from this Flickr URL.
I use your plugin using ltrim. The resulting value is “1298234230″. I’d like that resulting value to be placed into a variable.
The benefits of this would be:
1. I can organize my code in the page in such a way to have all of my values defined at the beginning of the page and use the variable throughout the page.
2. I can accomplish this with PHP, but then i have to turn on PHP on my template and I try to avoid that. This would help me do that.
3. Variable are simply cleaner and easier for me to read. So I’d like something to modify a string and put the result value into a variable. That would be soooo freakin cool!
The main instance I was thinking about was Flickr. I was consuming a Flickr feed with Magpie. I was using PHP to ltrim and rtrim the URL so I could get the UserID number. I couldn’t figure out how to do that with your plugin, but i could do it with PHP.
I think this would make all the difference in the world.
As far as how maybe it could work, i’d love to see this:
{exp:replace find="you" replace="we" var="Whatever_I_Want_Here"}
text you want processed
{/exp:replace}
{Whatever_I_Want_Here} would equal "text we want processed"
Does that sound cool?
Hi Low, Thanks for the plugin. I am sitting over it and can’t get something working though. I use anchor tags in local nav .EE creates trailing slashes when I use the href=”{path=’/something’}” after something, which breaks the link. How can I use the plugin to replace the / with nothing. Thanks
@Christian: you’ll have to use a regular expression. Something like:
{exp:replace find="\\/$" regex="yes"}{path="something"}{/exp:replace}#yourhashThat will get rid of the trailing slash.
Low,
I”m trying to get this to replace underscores with a space but it’s not working. I’m using your last segment trick but want to remove the underscores - unfortunately the way things are set up I can’t do this inside a weblog:entries tag which means no option for {title}
Here is the code I’m using now: (I tried it with and without the multiple=”yes” option but no dice)
{exp:replace find=“_” replace=“SPACE” }{last_segment}{exp:replace}
Hey Sean. Your closing tag isn’t closing:
{/exp:replace}Also, make sure you’re not using curly brackets in your code.
Thank-you. Feel really stupid about that mistake.
Piggy-backing on what Erwin asked, is there a way to pass in multiple find/replace regexes? preg_replace() does that by passing in arrays of regex find/replace pairs, but not sure how that’d work with your plugin. Any ideas?
Hi, I’m using a simple webform in a template to submit a small string of text to the address bar as part of query string (?q=TEXT) like this “www.websitedomain.com/?q=TEXT”. From there I’m using an EE url segment (segement_1) tag to pull in that text from the address bar after the form submits in parts of the page. But, I’m trying to strip out part of the url segment that is the query characters (?q=) and leave just the submitted text. But using the find and replace plugin seems to choke on the inclusion of a “?” and it won’t strip anything out if that’s included. Can you suggest a method to use to strip out the inclusion of a question mark (?q=) when processing with the plugin?
Thanks!
Rob
Sorry, I may have incorrectly misidentified the problem. I think it’s the nature of using EE url segments. I don’t think they pull in content when started with “#” “%” or “?” in them. Just a guess…
Rob, if a url contains a “?”, then anything after that is part of the Query String. If a url contains a “#”, then anything after that usually refers to an anchor somewhere on that page. If a url contains a “%”, then it’s usually url-encoded ( for a space, for example). In any of these cases (apart from the percentage sign), anything after is not part of the EE segments, and therefore not accessible via the {segment_x} variables.
When using this with the twitter_timeline plugin, how should the plugin tags be nested?
I am using your example from the ee forum to replace @username links. Here’s what I’ve tried:
{exp:low_replace find=”@([_a-zA-Z0-9]+)” replace=”@<a href=’http://twitter.com/$1′>$1</a>” regex=”yes”}
{exp:twitter_timeline type=”user” …
This seems to suppress any output from the twitter_timeline plugin. Am I making an obvious error?
Ryan, that code seems to work for me, both in EE 1.6.8 and 2.0.1. Make sure you use {exp:replace…} for 1.6.x and {exp:low_replace…} for 2.x and check closing tags, quotes etc.
Thank you for your response, Low. I did a test and confirmed that your plugin is working fine. (Turns out it’s the twitter_timeline modification I am trying to make that is causing the problem).
I spoke too soon :P
Links are working in twitter_timeline, and @username links are also working, but these two things are not working together. Here is my code. It still seems to me I might be breaking some nesting rules. Can I have a tag pair within your ‘low’ tag pair? (I am using ee2.0)
{exp:low_replace find=”@([_a-zA-Z0-9]+)” replace=”@<a href=’http://twitter.com/$1′>$1</a>” regex=”yes”}
{exp:twitter_timeline type=”user” user=”****” password=”****” limit=”5″ refresh=”15″}
<div class=”tweet”>
{status_relative_date}
{text}
</div>
{/exp:twitter_timeline}
{/exp:low_replace}
Ryan, the nesting is fine. In fact, I just tested your code in my EE2.0.1pb01, build 20100121 (not the trial or freelance version) and it works just fine. Are there any other add-ons that might interfere?
I am stumped. The only plugins I have installed are this one, and the twitter timeline (in addition to the Magpie RSS and XML default plugins). I appreciate your help. I will need to revisit this in a few weeks.
Hi Low,
I am using this plugin to find and replace text being output via Javascript for a Flowplayer-based playlist.
If a person enters a single quote into the text field (which has to be non-xhtml), the playlist breaks.
Is there a way with Find and Replace to find a single quote and replace with ’? I know it is possible for double quotes via QUOTE.
Chad, you should be able to use something like this:
{exp:replace find="'" replace="'"}Hi Low,
can I do this with, what is done with LG’s replace, with your replace.
I cant figure it out :-(
{exp:lg_replace:haystack needles="{cf_images backspace="1"}image_{row_count}|{/cf_images}"}
{cf_images}
{exp:lg_replace:replacement needle="image_{row_count}"}
{exp:imgsizer:size src="{image}" width="{image_size}" alt="{image_caption}" class="{image_align}"}
{/exp:lg_replace:replacement}
{/cf_images}
{/exp:lg_replace:haystack}
Paradise, LG Replace works differently than Low Replace. I’m afraid that what you’re trying to do cannot be achieved with Low Replace.
Hmpf you allready answered. Just found out where the difference is after trying the whole time to get this LG thing running. The only thing yours and LG’s have common is the name “replace”. LG’s is not a renaming thing its more a putting here putting there thing :-).
Sorry for waisting your time. EE is sometimes “trial and error” and allways learning by doing…
Hi Low, thanks for great plugin! Trying to get rid of some html. I want to completely delete a div. My original html is <div class=”imageright style=”width:xx”>TEXT</div> I want to delete the entire string.
Here’s what I’m attampting:
{exp:replace find=”<div class=”imageright”.*?</div>” replace=”" regex=”yes” }
Seems like when it gets to the ” before imageright, it stops the replacement.
I’m a newbie at regex — sorry, I’m trying to learn! Any suggestions? Thanks!
Brittany, if you need to replace a double quote, use the string
QUOTEinstead of".Hey Low — thanks for the feedback! I’d tried that based on your examples in the docs, but I just can’t get it to work. Here’s my code:
{exp:replace find=“<div class=QUOTEimagerightQUOTE.*?</div>” replace=“” regex=“yes” }{starter_text}{/exp:replace}
As you can see, the results are here: http://uvamagazine.org/mobile/article/uva_student_dies_in_haiti_earthquake/
no text is appearing in the body!
Having an issue with Mars Edit/Metaweblog & EE 1.6.8. The code for the youtube gets corrupted.
Specifically: ‘<’ and ‘>’ get converted to ‘<’ and ‘>’ respectively.
So if you enter <object>blah blah and save it to EE, it immediately comes back as <object>blah blah
I’m trying to use low_replace to solve this, but I’m wondering if I need a regex?
{exp:low_replace find=”<|>” replace= “<|>” multiple=”yes”}
{summary}
{body} –> eg:<object width=”425″ height=”344″>
{extended}
{/exp:low_replace}
Sorry.. not great with this - just trying to figure it out.
Thanks,
Nagib, please read the docs carefully. On the top it says you should use the tag
{exp:replace}— withoutlow_— if you’re using EE 1.x, which includes 1.6.8.HI Low,
Apologies.. I did do that - but it still makes no difference. Does this have to be done as a regex? Eg: The text that has < and > is contained with a variable such as {summary} and EE converts this to (&lessthan;) “& l t ;” I need it to stay as ‘ < ‘
Nagib, go to CP Home › Admin › Weblog Administration › Weblog Management › Edit Weblog Preferences and set the value “Default HTML formatting in weblog entries” to “Allow ALL HTML”.
That should probably do it, and you don’t even need the plugin.
Hi Low,
Already did that. When I enter this in EE direct it is fine, when I do it through Mars Edit it screws up and coverts the “<” to “l t ;”. On EE people mentioned your tool as the best way around it. That’s why I came here. I just need to find a way to prevent EE changing this when it receives a blog post from MarsEdit/Blogo/Ecto anything. I can’t believe I’m the only one experiencing the issue.
Hey Low — I’m pulling my hair out with this issue and I’m wondering if you have any ideas for me. I tried your suggestion:
{exp:replace find="<div class=QUOTEimagerightQUOTE.*?div>" replace="" regex="yes"}{starter_text}{/exp:replace}But still nothing shows! (as can be seen here: As you can see, the results are here: http://uvamagazine.org/mobile/article/uva_student_dies_in_haiti_earthquake/)
when I replace the QUOTE with actual quotation marks ” then everything up until the first quotation mark is removed, but it stops there.
(Sorry to repost, I’m desperate!)
Brittany, I’ve edited your comment above, ’cause the quotes around the parameter values were curly quotes instead of regular ones. You can actually try and copy/paste the above code and see if that works — maybe the curly quotes are in your template as well.
Low - thanks for all your help. It was functioning perfectly until I added a parameter.
{exp:replace find=“<div class=QUOTEimagerightQUOTE.*?div>|<div class=QUOTEimagecenterQUOTE.*?div>|<div class=QUOTEarticlesideQUOTE.*?div>|<div class=QUOTEimageleftQUOTE.*?div>” replace=“” regex=“yes”}{article_body}{/exp:replace}
All function EXCEPT for div class=”articleside” which remains in the text. You can see it here: http://uvamagazine.org/mobile/article/this_old_academical_village
(the div is around the paragraph titled “handyman’s delight”
I’ve checked for stupid stuff like curly quotes… I hope it’s not something like that again!
Thanks for your help, Low!!
I don’t think my code posted correctly (the dang quotes look curly, but i know they aren’t!) Let’s try again…
{exp:replace find="<div class=QUOTEimagerightQUOTE.*?div>|<div class=QUOTEimagecenterQUOTE.*?div>|<div class=QUOTEarticlesideQUOTE.*?div>|<div class=QUOTEimageleftQUOTE.*?div>" replace="" regex="yes"}{article_body}{/exp:replace}Hi Low,
I had my IT guy (who knows reg ex) look at this and he could not get it to perform (specifically the “articleside” variable). Any ideas?
Brittany, maybe you could try something like this:
{exp:replace find="<div class=QUOTE(imageright|imagecenter|articleside|imageleft)QUOTE.*?div>" regex="yes"}Untested, but should work, I think.
Thanks for getting back to me! But no luck, that didn’t work. I”m using find and replace in conjunction with html_strip, but I removed the html_strip and still it wasn’t working. Just doesn’t like that “articleside” div. Any other ideas would be appreciated.
I think this plugin might help me but I’m not certain. i have a client that has the registered trademark symbol throughout their site, in custom fields, and even in titles. Can this plugin be used the swap the special character ® with <sup>®</sup> so the thing is superscripted everywhere it appears in the site? And so the plugin tags would have to be at the start and end of each template, correct?
Low, trying to replace a ‘/’ (forward slash) in a string with an ‘_’ (underscore) and tried your suggestion as per your Nov 12th post to Christian, but can’t seem to get it working. Example string could have slash anywhere:
‘4659/GD’ or ‘4641/GD/SL’
Hope you can help.
Thanks
Brendan
Ignore me, too many days coding in a row and forget to close the tag pair.
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.
David, you could use an embed:variable or path.php variables for that. Remember that using the “title1|title2|title3″ syntax, you also need to use multiple=”yes”. But if you want to replace those with links, you’ll probably need to use a regular expression.
QB Marketing: Most likely, the ® character is changed into a html entity by EE. That means you’ll have to look at the source to see what the exact code is, then use that as your parameter. You’re right as to where to place the tags.
Hi Low,
I’m using EE 1.6.9 and the latest version of this plugin, 1.3.
I have a segment that contains a year (2009 or 2010), and I’m trying to output the segment in a h4 as 2010 if the segment is 2009, and 2011 if the segment is 2010 (don’t ask!).
I’ve used this plugin before without any issues, but for some reason, it keeps outputting the value as 2011 no matter whether the segment is 2009 or 2010. Here’s my code:
{exp:replace find=”2009|2010″ replace=”2010|2011″ multiple=”yes”}{segment_4}{/exp:replace}
Any ideas on this at all?
Thanks,
Stephen
Hi Low,
is there anyway to replace just the number 0 with ‘None’ and not affect multiples 10 20 30 etc?
Great plugin, has helped me a load!
Stephen, try swapping the values, so
find="2010|2009" replace="2011|2010". The replacement doesn’t happen instantaneously, but one after the other. Therefore, if a 2009 is replaced with 2010, and then the next replacement kicks in, it’ll replace 2010 with 2011. Turning the order around will keep that from happening.Shane, you’ll need a regex for that. If you’re wrapping it right around the variable, try something like this:
{exp:replace find="^0$" replace="None" regex="yes"}{some_var}{/exp:replace}Wasn’t expecting such a quick response!
Thanks Low, really appreciate it!
Shane