Psionicist
Explorer
Re: Better living through regular expressions
Yes, I and Liquide did something like that moments later I posted the above "solution".
Scarab said: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".