PHP spoiler tags pattern and replacement problem.

Any questions involving matching text strings to patterns - the pattern is called a "regular expression."

Moderator: General Moderators

Post Reply
Pint
Forum Newbie
Posts: 3
Joined: Sat Aug 13, 2005 12:23 pm

PHP spoiler tags pattern and replacement problem.

Post by Pint »

I'm trying to modify my xmb forum to use spoiler tags,
The part i'm having trouble with is getting the right replacement for the tags

Code: Select all

$patterns[] = "#\[spoiler\]([:a-z\\./_\-0-9%~]+){1}(\?[a-z=_\-0-9&;~]*)?\[/spoiler\]#mi";
        $replacements[] = '<div class="spoiler" style="padding: 3px;" align="center" width="100%"><a href="javascript://" OnClick="javascript: layerVis(\''.$rnd.'\', 1);">Reveal Spoiler</a><div align="left" id="'.$rnd.'" style="visibility: hidden;">\1</div></div>';
This replaces the spoiler tags with a reveal box or at least it's supposed to anyway.
The reveal spoiler part comes up but nothing else.

Here's the source code of that part in the page produced

Code: Select all

<div class="spoiler" style="padding: 3px;" align="center" width="100%"><a href="javascript://" OnClick="javascript: layerVis('',
1);">Reveal Spoiler</a><div align="left" id="" style="visibility: hidden;">Text</div></div>
Any ideas?
I should probably add that i know next to nothing about PHP and that i'm only starting to learn by adding hacks and modifications to my forum.

JCART | Please use

Code: Select all

tags when posting php code. Review [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url][/color]
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post by John Cartwright »

Moved to Regex.
Pint
Forum Newbie
Posts: 3
Joined: Sat Aug 13, 2005 12:23 pm

Post by Pint »

I did originally use php but it changed the

Code: Select all

javascript://
into

Code: Select all

javascript://
so i thought better of it.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

$rnd isn't set when the string is created.
Pint
Forum Newbie
Posts: 3
Joined: Sat Aug 13, 2005 12:23 pm

Post by Pint »

Thank you so much. It's working perfectly now i think.
Feel a little :oops: though....

Thanks :D
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Post by Chris Corbyn »

Pint wrote:Feel a little :oops: though....
Don't. Everyone does stuff like that even when you've been doing it for years ;)

Welcome to the forums :D
Post Reply