You are not logged in.
John, if you’re using rah_function as a container tag, whatever is in the container tag is fed to the called function as the first argument. In this case you want it to be the 3rd argument, because the first and second argument for the preg_replace call is the regex and replacement respectively.
Gocom, perhaps you can add a magic attribute that indicates where the $thing should be used, so John (and others) could do something like this:
<txp:rah_function call="preg_replace" pattern="'\s|\t|\r|\n'" replacement="" thing="here">
some thing
</txp:rah_function>
Offline
Thank you Redbot! I’m using the tag to wrap the text that I want to find and replace patterns in, just like in the pax_grep example above. The purpose of this example is to strip out whitespace characters from the wrapped text. Does that make sense?
Offline
johnstephens wrote:
Thank you Redbot! I’m using the tag to wrap the text that I want to find and replace patterns in, just like in the pax_grep example above. The purpose of this example is to strip out whitespace characters from the wrapped text. Does that make sense?
Yes, I understood what you are trying to achieve. You should use the tag in his self-enclosing form like this:
<txp:rah_function call="preg_replace" pattern="'\s|\t|\r|\n'" replacement="" subject="My source" />
You have to insert the text you want to change as the third argument.
Offline
That worked, thanks again!
Offline
Version 0.2 released. Changes:
thing. Thanks you ruud for suggestion.Rah-plugins | What? I’m a little confused… again :-) <txp:is_god />
Offline
Oh, whow!
That’s a neat thing. Thank you!
Offline
Hi Gocom,
I’m not sure if this is a bug, but when I use:
<txp:rah_function call="safe_count" table="textpattern" where='Section="<txp:section />"' />
I get one more article in the count than exists, for any section I specify. Could this be something to do with MySQL counts starting at 1 versus PHP starting at 0?
Great plugin, btw!
“People who value their privileges above their principles soon lose both.”
Dwight D. Eisenhower
Offline
speeke wrote:
Great plugin, btw!
Sarah, nice to see that you like the plugin.
Could this be something to do with MySQL counts starting at 1 versus PHP starting at 0?
Don’t know what PHP starting point you are meaning, but the count starts from one; The first found row is the number one.
safe_count() function you are calling with the tag, is part of Textpattern’s core library. It runs a standard count query:
select count(*) from textpattern where Section="name"
Remember that the count also counts draws and hidden articles. If the count is rendered wrong with plain query too, and you are certain that it is wrong, the table/index might be a bit broken. Running a repair helps with that. You can use repair with phpMyadmin, for example.
If you use specialchars in the value (", ', \ etc), you need to escape the chars by using doSlash. Something like:
<txp:rah_function table="textpattern" thing="here">
foo='<txp:rah_function call="doSlash">bar</txp:rah_function>' and bar='foo'
</txp:rah_function>
Rah-plugins | What? I’m a little confused… again :-) <txp:is_god />
Offline
Apologies, I forgot to add and status=4 – was also counting sticky articles. All good.
“People who value their privileges above their principles soon lose both.”
Dwight D. Eisenhower
Offline
Hello,
can we put this : <txp:rah_function call="safe_count" table="textpattern" where='Category="peintres"' /> for search the number of article in a category (I use rss_unlimited_categorie)
in a txp variable?
(I test that : <txp:variable name="test" value='<txp:rah_function call="safe_count" table="textpattern" where='Category="peintres" ' />' /> but this not right.)
Added code formating -Gocom
Last edited by Gocom (2010-06-21 08:17:06)
Offline