[pmwiki-users] Re: Re: data from wiki page rather than file
chr at home.se
chr at home.se
Fri May 6 04:19:05 CDT 2005
On Thu, 5 May 2005, Patrick R. Michaud wrote:
> > Maybe it'd be convenient for cookbook authors if there was a function that
> > they could call to extract text data from wiki pages. Maybe the function
> > could be invoked like this:
> > $textArray = GetDataFromPage($page, $OptStartTag, $OptEndTag);
> > where if there are no optional tags, the entire page is returned as a
> > string in $textArray.
>
> Perhaps, or maybe we just publish the code idioms:
Works for me. Do we have a page somewhere for stuff like this? At first I
thought something like PmWiki/API could describe ReadPage() etc, but this
is more like an FAQ entry for cookbook authors.
Q: How can I extract the text of a wiki page?
> $apage = ReadPage('Group.SomeOtherPage', READPAGE_CURRENT);
> $atext = $apage['text'];
> # full text is in $atext
>
> or
Q: How can I extract text within tags from a wiki page?
> $apage = ReadPage('Group.SomeOtherPage', READPAGE_CURRENT);
> preg_match_all(
> '/\\(:mytag:\\)(.*?)\\(:mytagend:\\)/i',
> $apage['text'],
> $match);
> $textArray = $match[1];
> # extracted components are in $textArray[1]
> foreach ($textArray[1] as $x) { echo $x, "\n"; }
> I think there could be too many variations in the formats for
> (:mytag:) and (:mytagend:) to be usefully encoded as simple
> variables.
I was actually thinking each tag could be regular expression, but that
might not be enough (as in your example with tar arguments).
...
> So I think maybe it's better to just give "here's the base
> code fragment" and let recipe writers customize it to suit.
Sounds good, we'll just need to document it. If we ever see that a certain
code fragment is very frequently used, it could then be turned into a
function.
/Christian
--
Christian Ridderström, +46-8-768 39 44 http://www.md.kth.se/~chr
More information about the pmwiki-users
mailing list