Glyde Posted March 22, 2007 Share Posted March 22, 2007 I'm writing a tag parser (basically BBCode) for a project I'm developing. Currently, to parse colors, I have been looking at something like this: $postBody = preg_replace("@\[color=((#[0-9A-F]{3,6})|([A-Z\-]+))\](.+?)\[/color\]@is", "<span style='color: $1'>$4</span>", $postBody); However, I want to be looking for the last index of [/color] in the code, not the first. For example, I want: [color=#CCC]test[color=#000]more[/color]text[/color] At first glance, you would expect the "more" text to become #000, which it does. But you would also expect "text" to be #CCC, but it's not. It becomes #000. Because preg_match searches for the next index of [/color] after finding , instead of searching for the last. Is there any way to indicate that I want to search for the last index of something? If not, I'll have to look for my alternative I guess which was using strpos and strrpos in conjunction. Quote Link to comment Share on other sites More sharing options...
Glyde Posted March 22, 2007 Author Share Posted March 22, 2007 I'm just going to my strpos original idea. Thanks anyways. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.