MetaPost 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.
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.
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.
__________________ 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.
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..
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
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).
$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.
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.
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)