[pmwiki-users] php q

H. Fox haganfox at users.sourceforge.net
Mon Jul 16 10:08:50 CDT 2007


On 7/16/07, noskule <noskule at gmx.net> wrote:
> hi list
> I have some trouble to get this php code to runn properly, could please
> someone giving me a hand?
>
> I try to get the basename of a page:
>
>     SomeGroup.SomeName-Topic-12 -> SomeGroup.SomeName
>
> GLOBAL $TopicBaseName,$CommentBaseName;
>
> $name = PageVar($pagename, '$Name');
> $backnametopic = explode('-Topic-',$name);
> $backnametopic = $backnametopic[0];
> $FmtPV['$TopicBaseName'] = $backnametopic;
>
> this work like expected.
>
>
> SomeGroup.SomeName-Topic-12-Comment-3 -> SomeGroup.SomeName-Topic-12
>
> $name = PageVar($pagename, '$Name');
> $backnamecomment = explode('-Comment-',$name);
> $backnamecomment = $backnamecomment[0];
> $FmtPV['$CommentBaseName'] = $backnamecomment;
>
> this don't work and gives me: -12

I think this would work both places:

   $backname = preg_replace("/-Topic-.*\$/", '', $name);

in other words

   $name = PageVar($pagename, '$Name');
   $backname = preg_replace("/-Topic-.*\$/", '', $name);
   $FmtPV['$BackName'] = "'$backname'";

or maybe

   $name = PageVar($pagename, '$Name');
   if (preg_match("/-Topic-.*\$/", $name)) {
     $backname = preg_replace("/-Topic-.*\$/", '', $name);
     $FmtPV['$BackName'] = "'$backname'";
   }

makes {$BackName} always return the page's name up to the first "-" in
"-Topic-".

Hagan



More information about the pmwiki-users mailing list