Textpattern CMS support forum
You are not logged in. Register | Login | Help
- Topics: Active | Unanswered
rah_replace - Search and replace
Download the plugin here.
The plugin, rah_replace, returns contained content with all occurrences replaces with given replacements. It supports multiple replacements.
<txp:rah_replace from="something,to,change" to="into">
This is something that is going to change into.
</txp:rah_replace>
Already a bit older(ish) plugin of mine. Noticed that it didn’t have a support topic, so decided to create one. Also, today is the day when rah_replace got it’s first update; Version 0.2 which adds delimiter
attribute.
Last edited by Gocom (2012-07-12 03:19:29)
Offline
#2 2009-08-16 20:47:00
- els
- Moderator
- From: The Netherlands
- Registered: 2004-06-06
- Posts: 7,458
Re: rah_replace - Search and replace
Hi Jukka, nice plugin, thanks! Is it possible to replace line endings (\r\n etcetera) as well? I tried it using all kind of quotes, but can’t get it to work. I’m trying to use it around the output_form tag in <body class="<txp:output_form form="body_class" />">
. The form contains a lot of conditional tags, so in the end the output is something like this:
<body class="
[lots of blank lines]
class-name
[more lots of blank lines]
">
And yes, I can remove the line endings from my form, but for legibility I’d rather not do that.
Offline
Re: rah_replace - Search and replace
<body class="<txp:php>echo str_replace("\r\n", '', output_form(array('form'=>'body_class')));</txp:php>">
edit: fixed code
Last edited by ruud (2009-08-16 22:07:34)
Offline
#4 2009-08-16 21:34:59
- els
- Moderator
- From: The Netherlands
- Registered: 2004-06-06
- Posts: 7,458
Re: rah_replace - Search and replace
Thanks, Ruud :) But:
<body class="<br />
<b>Warning</b>: Unexpected character in input: '\' (ASCII=92) state=1 in <b>/path/to/textpattern/publish/taghandlers.php(3127) : eval()'d code</b> on line <b>1</b><br />
<br />
<b>Parse error</b>: syntax error, unexpected T_STRING in <b>/path/to/textpattern/publish/taghandlers.php(3127) : eval()'d code</b> on line <b>1</b><br />
">
Offline
Re: rah_replace - Search and replace
Els wrote:
Hi Jukka, nice plugin, thanks! Is it possible to replace line endings (\r\n etcetera) as well?
Well not literally, but you can really easily replace line breaks. For example:
<txp:rah_replace from="
" to="">
1
2
3
</txp:rah_replace>
becomes:
123
Last edited by Gocom (2009-08-16 22:08:37)
Offline
#6 2009-08-16 22:09:36
- els
- Moderator
- From: The Netherlands
- Registered: 2004-06-06
- Posts: 7,458
Re: rah_replace - Search and replace
Ah, I see, thanks. Meanwhile, Ruud solved the problem elsewhere, so I won’t be needing rah_replace at the moment. But I’ll certainly keep it in mind!
Offline
Re: rah_replace - Search and replace
Rah_replace v0.3 is now out. The release includes small performance tweaks.
Offline
Re: rah_replace - Search and replace
Hello Jukka,
the new version is maybe only working on textpattern 4.4 and up. I recognized, that this function stopped working after updating from v.0.2 to v0.3:
<txp:variable name="schlagwort"><txp:rah_replace from='/tag/,/?t=,",/' to=""><txp:php>$tag=$_SERVER['REQUEST_URI'];echo urldecode($tag);</txp:php></txp:rah_replace></txp:variable>
It is a website with textpattern 4.2 and mlp.
The same function is doing fine on a textpattern 4.4 site. So I had only to return to 0.2 on the first site …..
Thanks again for your plugins!!!
Offline
Re: rah_replace - Search and replace
whocarez wrote:
the new version is maybe only working on textpattern 4.4 and up.
The same function is doing fine on a textpattern 4.4 site.
Andreas, that’s strange. The plugin uses no TXP version depended code, and should be compatible with any 4.x release. Used version shouldn’t being the effecting factor, instead I believe the problem lies somewhere else.
Edit. Ran small test with your code on TXP 4.2.0 + PHP 5.3.5 box and it worked fine. When requested ?foo/bar/foobar/tag/
, the returned variable holded ?foobarfoobar
as expected.
Last edited by Gocom (2011-04-30 00:51:47)
Offline
Re: rah_replace - Search and replace
ok, so it is probably an mlp issue. anyway, I could step back to v0.2.
Offline
#11 2011-07-01 00:56:55
- GugUser
- Member
- From: Quito (Ecuador)
- Registered: 2007-12-16
- Posts: 1,473
Re: rah_replace - Search and replace
Does someone detect why the following code in a page with rah_replace doesn’t work?
<txp:output_form form="head" />
<body id="<txp:section />"><txp:rah_replace from="http://domain.de" to="">
<div id="wrapper">
<txp:output_form form="slider" /><txp:if_section name="impressum,kontakt"></txp:rah_replace></txp:if_section>
<section>
<h1><txp:if_section name="xy">xy title<txp:else />other title</txp:if_section></h1>
<txp:article limit="1" sort="position asc" form="artikel" />
</section><txp:if_section name="impressum,kontakt"><txp:rah_replace from="http://domain.de" to=""></txp:if_section>
<txp:output_form form="nav" />
<txp:output_form form="footer" /></txp:rah_replace>
</div>
</body>
</html>
It works only for the sections “impressum” and “kontakt”. In the other sections the forms “nav” and “footer” are not parsed. I don’t see where I made a mistake.
Offline
#12 2011-07-01 01:01:55
- els
- Moderator
- From: The Netherlands
- Registered: 2004-06-06
- Posts: 7,458
Re: rah_replace - Search and replace
You are closing the rah_replace tag outside the if_section conditional (and opening it inside…)
Edit: ah, wait, I see now what you are doing. You don’t want to apply rah_replace to the <section>
part, right?
Last edited by els (2011-07-01 01:05:23)
Offline