Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#1 2009-04-16 11:51:36

THE BLUE DRAGON
Member
From: Israel
Registered: 2007-11-16
Posts: 637
Website

using ied_replacer or str_replace for a custom field

Hey I want to do some search and replace into a custom field
now there is the plugin name ied_replacer that is great
but don’t know how to make it work with custom fields too
this is how it works:

extract(lAtts(array(‘what’ => false), $atts));
switch ($what) {
case ‘body’: $what=$GLOBALS[‘thisarticle’][‘body’]; break;
case ‘excerpt’: $what=$GLOBALS[‘thisarticle’][‘excerpt’]; break;
case ‘title’: $what=$GLOBALS[‘thisarticle’][‘title’]; break;
case ‘message’: $what=$GLOBALS[‘thiscomment’][‘message’]; break;
}
return str_replace(array_keys($smilies), array_values($smilies), $what);

so I think I need to add another line of case
but I don’t know what global to use
and where to write the name of the custom field
or to write custom_1 instead of the name
anyone know please?

if can’t do this with ied_replacer so how can I use str_replace to replace 3 times in one function?
this is how I can use it to replace 1 thing, but I need to replace 3 things:

function custom_replacer ($atts){
extract(lAtts(array(
‘replace’ => ‘i’,
‘with’ =>‘I’,
‘where’ => ‘<txp:custom_field name=“blabla” />’
),$atts));
return str_replace($replace, $with, $where);
}

<txp:custom_replacer where='<txp:custom_field name="blabla" />' />

but again it’s only replace one thing and I need to replace 3
will love to get some help with this please!
thanks =)

Offline

#2 2009-04-16 12:15:50

Gocom
Developer Emeritus
From: Helsinki, Finland
Registered: 2006-07-14
Posts: 4,533
Website

Re: using ied_replacer or str_replace for a custom field

Possibly it would be easier to just use PHP or a plugin that allows you just to simply replace, like rah_replace does.

For example:

<txp:rah_replace from="i" to="I">
	<txp:custom_field name="blabla" />
</txp:rah_replace>

Or if multiple, comma seperated:

<txp:rah_replace from="i,dog" to="I,cat">
	<txp:custom_field name="blabla" />
</txp:rah_replace>

Last edited by Gocom (2009-04-16 12:16:22)

Offline

#3 2009-04-16 12:51:33

THE BLUE DRAGON
Member
From: Israel
Registered: 2007-11-16
Posts: 637
Website

Re: using ied_replacer or str_replace for a custom field

that is so sweet!
thank you Gocom!

I just made a small change in the plugin code I changed , to + because I’m working on a newsletter and that means inline css
so if I have a css code that include , like font: normal 11px arial, sans-serif; it will think it needs to stop
so I just change:

$from = explode(‘,’,$from);
$to = explode(‘,’,$to);

into

$from = explode(‘+’,$from);
$to = explode(‘+’,$to);

thanks again! ;)

Offline

#4 2009-04-16 13:42:15

Gocom
Developer Emeritus
From: Helsinki, Finland
Registered: 2006-07-14
Posts: 4,533
Website

Re: using ied_replacer or str_replace for a custom field

THE BLUE DRAGON wrote:

I just made a small change in the plugin code I changed , to +

rah_replace version 0.2 includes delimiter attribute. Released the girl 12 minutes ago.

Offline

#5 2009-04-16 13:59:13

THE BLUE DRAGON
Member
From: Israel
Registered: 2007-11-16
Posts: 637
Website

Re: using ied_replacer or str_replace for a custom field

cool!
=)

you forgot to insert the attribute: delimiter in your “Example #4” on your site

Offline

#6 2009-04-16 14:23:32

Gocom
Developer Emeritus
From: Helsinki, Finland
Registered: 2006-07-14
Posts: 4,533
Website

Re: using ied_replacer or str_replace for a custom field

THE BLUE DRAGON wrote:

you forgot to insert the attribute: delimiter in your “Example #4” on your site

Thank you. Fixed.

Offline

Board footer

Powered by FluxBB