![]() |
Regex help?
I am working on an app and currently looking to create a plugin to quickly display images from a folder using a quick tag.
I figured in order to do so I would replace ... {gallery=/path/to/images} In the content page, replacing it with formatted HTML showing the images in the folder specified. I am no good with regex (still painfully trying to learn though), and was hoping someone could help me with the match to get the /path/to/images portion of the tag and replacing the entire thing with my HTML. |
You could use preg_replace_callback() to replace that part with a gallery:
PHP Code:
|
Thanks, I will give that a try. I have put regex off for so long, really need to work with it more.
This is the pattern I had, but it currently is half working... Code:
"/{gallery=(.*)}/i"Code:
// The main fileA small note, the regex you listed above didn't work until I removed the ^ and $ in the pattern. |
Regular expressions are fairly easy to pick up, they're just a little harder to master.
php Code:
The above is just an example of one way to improve your expression, I'll leave the insertion of the gallery to you since you seem to have a handle on it. Uncomment the first one using the original pattern (and comment the second) and you'll see what I'm referring to. .* is powerful, but almost always misused. Try to avoid it while you're learning and you'll pick up tricks that will help you build much more complex patterns down the road. |
| All times are GMT. The time now is 05:25 AM. |
Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0