Go Back   EN World D&D / RPG News > Meta - Forums About Forums > Meta

Meta Post comments and questions about the messageboards and other parts of EN World. If you have a problem, this is where to go. Moderator email addresses are posted here.

 
Share LinkBack Thread Tools Display Modes
Old 21st October 2002, 12:26 PM   #1 (permalink)
DEX: 4
 
Liquide's Avatar
 
Join Date: Jan 2002
Location: Katrineholm, Sweden
Posts: 814
Liquide Goblin Sharpshooter (Lvl 2)
Send a message via ICQ to Liquide Send a message via MSN to Liquide
[OT]PHP and regular expressions

Well I need some PHP help and if there are someone that is good at this and can help me out I would become very happy

I have a string in an array that is called $content[TheDesc] in this string I want to search for a specific pattern and pass it along to the function dopicencode().

The pattern is [IMGCODE]string[/IMGCODE] (observe that the IMGCODE and /IMGCODE is enclosed in brackets inside the $content[TheDesc]). The string that is enclosed in [IMGCODE] and [/IMGCODE] I want to send along to the dopicencode() function.

The result of the dopicencode() I want to return and use as a replacement of the whole [IMGCODE]string[/IMGCODE] pattern.

Anyone that knows enough of PHP to help me out with this
__________________
-Liquide
EN World Compatriot

7th of July, 1987 - 19th of December, 2002
Linus fellow compatriot and a dear friend may he rest in peace.
__________________
Three disks to the IBM kings under Wall Street, Seven for the Compaq gurus who slaved to get rich, Nine for the Commodore Techs doomed to die...

One for the dark lord who sits upon his dark throne in the land of Renton where the Shadow lies...

One OS to rule them all...
One OS to crash them...
One OS to bring them all into darkness and bind them in the land of Renton where the Shadow lies.
Liquide is offline   Reply With Quote
Old 21st October 2002, 12:29 PM   #2 (permalink)
DEX: 4
 
Liquide's Avatar
 
Join Date: Jan 2002
Location: Katrineholm, Sweden
Posts: 814
Liquide Goblin Sharpshooter (Lvl 2)
Send a message via ICQ to Liquide Send a message via MSN to Liquide
The code I tried that didn't work

OK I'm fairly new to PHP and this is what I tried at first but it just returns a foobar result.

$imageTemp = array ("[IMGCODE]","[/IMGCODE]");
$replaceTemp = array("","");
$strTemp = str_replace($imageTemp,dopicencode($replacetemp),$ content[TheDesc]);

So if you can help me out, HEEEEELP! I need it
__________________
-Liquide
EN World Compatriot

7th of July, 1987 - 19th of December, 2002
Linus fellow compatriot and a dear friend may he rest in peace.
__________________
Three disks to the IBM kings under Wall Street, Seven for the Compaq gurus who slaved to get rich, Nine for the Commodore Techs doomed to die...

One for the dark lord who sits upon his dark throne in the land of Renton where the Shadow lies...

One OS to rule them all...
One OS to crash them...
One OS to bring them all into darkness and bind them in the land of Renton where the Shadow lies.
Liquide is offline   Reply With Quote
Old 21st October 2002, 12:38 PM   #3 (permalink)
Registered User
 
Mathew_Freeman's Avatar
 
Join Date: Jan 2002
Location: London, England
Posts: 6,148
Mathew_Freeman Orc Berserker (Lvl 4)
This should be in meta, of course.
__________________
DM of Adventure Path Story Hour (now in Thunderspire Labyrinth!): Ryam Plays Dice - updated 8th June 09 (campaign on indefinite hiatus).
Player in Swordlands Story Hour:
Interview with a Fey - updated 15th June 09. News just in - this campaign may be restarting in the near future! Watch this space!

I also have the singular honour of being Rouseketeer #20.
Mathew_Freeman is offline   Reply With Quote
Old 21st October 2002, 12:41 PM   #4 (permalink)
DEX: 4
 
Liquide's Avatar
 
Join Date: Jan 2002
Location: Katrineholm, Sweden
Posts: 814
Liquide Goblin Sharpshooter (Lvl 2)
Send a message via ICQ to Liquide Send a message via MSN to Liquide
my bad, I hope a mod can move it along
Liquide is offline   Reply With Quote
Old 21st October 2002, 01:33 PM   #5 (permalink)
Registered User
 
Join Date: Jan 2002
Posts: 1,823
Psionicist Goblin Sharpshooter (Lvl 2)
Code:


$content[TheDesc] = "bblah blah hahahah [IMGCODE]Liquide[/IMGCODE] i roxor";

$ImgCodeBegin = "[IMGCODE]";
$ImgCodeEnd = "[/IMGCODE]";

if(strstr($content[TheDesc],$ImgCodeBegin))
{
	$PosBegin = strpos($content[TheDesc], $ImgCodeBegin) + strlen($ImgCodeBegin);
	$PosEnd = strrpos($content[TheDesc], $ImgCodeEnd);
	$ChunkedString = substr($content[TheDesc], $PosBegin, ($PosEnd - $PosBegin));

	echo $ChunkedString;

	//dopicencode($ChunkedString);
}
 
Some comments in Swedish, I'm pretty damn tired

Ovanståande fungerar, men enbart på en bild per sträng. DEt fungerar inte så bra om $content[TheDesc] = "bblah blah hahahah [IMGCODE]Liquide[/IMGCODE] i roxor [IMGCODE]Bild2[/IMGCODE]";
exempelvis.

Du kan ju experimentera lite med det. Jag hatar stränghantering i PHP.
__________________
The river sparkles and dances on the rocks.
At night, it flows deep and strong.

Last edited by Psionicist; 21st October 2002 at 01:33 PM..
Psionicist is offline   Reply With Quote
Old 21st October 2002, 01:37 PM   #6 (permalink)
WotC's bitch
 
hong's Avatar
 
Join Date: Jan 2002
Location: Australia
Posts: 19,403
hong Gnoll Huntmaster (Lvl 5)
Quote:
Originally posted by Psionicist
Code:


$content[TheDesc] = "bblah blah hahahah [IMGCODE]Liquide[/IMGCODE] i roxor";

$ImgCodeBegin = "[IMGCODE]";
$ImgCodeEnd = "[/IMGCODE]";

if(strstr($content[TheDesc],$ImgCodeBegin))
{
	$PosBegin = strpos($content[TheDesc], $ImgCodeBegin) + strlen($ImgCodeBegin);
	$PosEnd = strrpos($content[TheDesc], $ImgCodeEnd);
	$ChunkedString = substr($content[TheDesc], $PosBegin, ($PosEnd - $PosBegin));

	echo $ChunkedString;

	//dopicencode($ChunkedString);
}
 
Hmm. So PHP is basically C with dollar signs. Am I correct?

Anyways, I always thought PHP was that funky encryption thingamajig thought up by Phil Zimmerman (he of PKZIP).


Hong "or was that PCP?" Ooi

Last edited by hong; 21st October 2002 at 01:37 PM..
hong is offline   Reply With Quote
Old 22nd October 2002, 03:52 PM   #7 (permalink)
Registered User
 
Join Date: Jan 2002
Location: Stockholm, Sweden
Posts: 193
Scarab Goblin Sharpshooter (Lvl 2)
Send a message via ICQ to Scarab
Better living through regular expressions

Oh my. That's an awful lot of code for something that can be done with two quick regular expressions. And ugly C-style code at that.

Well. Let me give it a shot and show you how it's done the PHP way.

Code:
$content[TheDesc] = <whatever your content is>;

// Regular expression to get all occurances of "[IMGCODE].*[/IMGCODE]"
preg_match_all("/\[IMGCODE\](.*)\[\/IMGCODE\]/", $content[TheDesc], $contentmatch);

// Loop through result array and perform replace
foreach($contentmatch[1] as $replace) {
	$content[TheDesc] = preg_replace("/\[IMGCODE\](.*)\[\/IMGCODE\]/", dopicencode($replace), $content[TheDesc], 1);
}

// Done!

return $content[TheDesc];
I haven't tried it, but it should work. Or at least give you a good start. Better living through regular expressions! Impress your friends with a regular expression party trick! Defeat your enemies with your regular expression kung fu! Regular expressions make your teeth shiny and improves your sex life!

Crap. Bostream is giving me problems right now. Well, I'll post as soon as it's up and running.

Hong: That's PGP you're thinking about.
__________________
By the edge of those wilds warriors had charged
But now the year and the generals were gone
And the grass grew in the armors hollow on the hills.

-- The Graymere Annals, 3704 CE
Scarab is offline   Reply With Quote
Old 22nd October 2002, 04:43 PM   #8 (permalink)
Silver Flame Archivist
 
drothgery's Avatar
 
Join Date: Jan 2002
Location: San Diego, CA
Posts: 8,102
drothgery Goblin Sharpshooter (Lvl 2)
Quote:
Originally posted by hong
Hmm. So PHP is basically C with dollar signs. Am I correct?
Only to the extent that Java is C with classes.

PHP is pretty much a stripped down, web-focused Perl (or at least that's what a looks like to someone with minimal exposure to PHP; I do my web programming in ASP.NET/VB.NET).
__________________
Dave Rothgery

PBP
Spoiler:

My EnWorld Blog
Republic and Empire
Buffverse M&M game

Characters
Active
Sanne Bacher d'Lyrandar in S@squ@tch's Against the Giants - Team Black

Inactive
Istara Kandorian in Ankh-Morpork Guard's Star Wars: Rebels with Style
Eric Hassel (Quarterback) in Jemal's Mutant High
Sariel in Rumspringa's Keep on the Shadowfell
Khalia ir'Indari in DEFCON1's Eye of the Lich Queen
Serrana Vao in Karl Green's Knights of the Old Republic (with 213 things Serrana can't do in the Jedi Order)
Italimelk in Living ENWorld
Daellin ir'Ayellan in stonegod's Expedition to Castle Ravenloft
drothgery's Victorian Eberron game
Star Wars/KotOR Era - The Second K'ril Incursion
drothgery is offline   Reply With Quote
Old 22nd October 2002, 04:50 PM   #9 (permalink)
WotC's bitch
 
hong's Avatar
 
Join Date: Jan 2002
Location: Australia
Posts: 19,403
hong Gnoll Huntmaster (Lvl 5)
Re: Better living through regular expressions

Quote:
Originally posted by Scarab

Code:

$content[TheDesc] = <whatever your content is>;

// Regular expression to get all occurances of "[IMGCODE].*[/IMGCODE]"
preg_match_all("/\[IMGCODE\](.*)\[\/IMGCODE\]/", $content[TheDesc], $contentmatch);

// Loop through result array and perform replace
foreach($contentmatch[1] as $replace) {
	$content[TheDesc] = preg_replace("/\[IMGCODE\](.*)\[\/IMGCODE\]/", dopicencode($replace), $content[TheDesc], 1);
}

// Done!

return $content[TheDesc];

 
Wow. If you look at that code reeeaaally closely, it starts to rotate!

Quote:

Hong: That's PGP you're thinking about.
I think you are confused, "Scarab", if that is your real name. Everyone knows PGP is a drug that people serve at parties. Do not confuse PGP with PCP, which is Phil Catz's Privacy program, or with PNP, the plug and play protocol used by ISO-certified modems.

You should be glad I'm here to correct your grevious mistakes. In the future, please check your facts before posting nonsense to UNsenet bboards. I always do.

HTH!
hong is offline   Reply With Quote
Old 22nd October 2002, 05:15 PM   #10 (permalink)
Registered User
 
Baron Von StarBlade's Avatar
 
Join Date: Jan 2002
Location: Chicago
Posts: 261
Baron Von StarBlade has disabled Experience Points
Send a message via Yahoo to Baron Von StarBlade
Hong has temporarily dethroned PirateCat as my hero.
__________________
-BvS

Oderint dum metuant

http://www.burningmelon.com
Baron Von StarBlade is offline   Reply With Quote
Old 22nd October 2002, 05:22 PM   #11 (permalink)
Registered User
 
Join Date: Jan 2002
Posts: 1,823
Psionicist Goblin Sharpshooter (Lvl 2)
Re: Better living through regular expressions

Quote:
Originally posted by Scarab
Oh my. That's an awful lot of code for something that can be done with two quick regular expressions. And ugly C-style code at that.

Well. Let me give it a shot and show you how it's done the PHP way.

Code:
$content[TheDesc] = <whatever your content is>;

// Regular expression to get all occurances of "[IMGCODE].*[/IMGCODE]"
preg_match_all("/\[IMGCODE\](.*)\[\/IMGCODE\]/", $content[TheDesc], $contentmatch);

// Loop through result array and perform replace
foreach($contentmatch[1] as $replace) {
	$content[TheDesc] = preg_replace("/\[IMGCODE\](.*)\[\/IMGCODE\]/", dopicencode($replace), $content[TheDesc], 1);
}

// Done!

return $content[TheDesc];
I haven't tried it, but it should work. Or at least give you a good start. Better living through regular expressions! Impress your friends with a regular expression party trick! Defeat your enemies with your regular expression kung fu! Regular expressions make your teeth shiny and improves your sex life!

Crap. Bostream is giving me problems right now. Well, I'll post as soon as it's up and running.

Hong: That's PGP you're thinking about.
Yes, I and Liquide did something like that moments later I posted the above "solution".
__________________
The river sparkles and dances on the rocks.
At night, it flows deep and strong.
Psionicist is offline   Reply With Quote
Old 23rd October 2002, 07:22 AM   #12 (permalink)
Shadowfell Tour Guide
 
Dakhran the Dark's Avatar
 
Join Date: Jan 2002
Location: Western MD, USA
Posts: 114
Dakhran the Dark Goblin Sharpshooter (Lvl 2)
Ack...someone beat me to it. Then again, I did spend the last five hours trying to figure out why my computer kept powering off and losing CMOS settings...

Oh, well. *bows to Scarab*
__________________

"What kind of dark wizard in league with nameless forces of primordial evil are you that you can't even make a successful sanity check versus boredom?" (8-bit Theatre)
Dakhran the Dark is offline   Reply With Quote
Old 23rd October 2002, 07:34 AM   #13 (permalink)
Registered User
 
MeepoTheMighty's Avatar
 
Join Date: Feb 2002
Location: Kalamazoo, MI
Posts: 2,112
MeepoTheMighty Goblin Sharpshooter (Lvl 2)
Send a message via ICQ to MeepoTheMighty Send a message via AIM to MeepoTheMighty Send a message via Yahoo to MeepoTheMighty
The boards are always best when hong's drunk.
__________________


MeepoTheMighty is offline   Reply With Quote


Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


And yet another word from our sponsors
Visit Our Sponsors
Visit Our Sponsors... Again
Powered by vBadvanced CMPS v3.0.1

All times are GMT +1. The time now is 08:07 PM.


Site Contents © 2008 ENWorld
PHP Ajax Multimedia Web Framework © 2008 Digital Media Graphix
Powered by vBulletin® Version 3.8.0 Beta 1
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.2.0

"Vault Data" powered by VaultWiki v2.5.1.
Copyright © 2008 - 2009, Cracked Egg Studios.