I've been pulling my hair out trying to figure out how to do this, so I figured I'd come on over here and see if anyone might have some insight. I've always gotten good information from this site, so I'm hoping to keep the tradition alive! 🙂
Ok, I'll try to make this brief, but there's a bit to is so I don't know.
I'm trying to pull various pieces of information out of a multiline variable based on a regex search, and then use that information to query a db, then do a search and replace with the results back into the original varible.
For example, in my software I have a multi-line variable, which we'll say contains the following:
random text, blah blah blah OLINK1 345 OLINK2 Link Text OLINK3 other random text, blah blah blah, OLINK1 648 OLINK2 Second Link Text OLINK3
Here are the steps I now want to perform on this data, and I just can't get it to work:
- Retrieve each reference of OLINK1 # OLINK2 (text) OLINK3 out of this variable
- Pull the "#" out and use this to query on a database
-With the information that's returned from the DB, do a search and replace on the original variable
I used to have some code that just did a straight search/replace for the OLINK tags, but now that I'm using apache url rewriting it's not as easy as just replacing, as I need to pull the 'pretty url' from the database first.
I've got most of it working, but figuring out how to cycle through the variable and pull out all the "#"s is driving me batty.
Basically, I'm trying to turn this:
OLINK1 # OLINK2 (text) OLINK3
into:
<a href="prettyurl from database based on #">(text)</a>
If anyone has any suggestions I'm willing to try anything. I've written a ton of code in my day, but this one's got me completely stumped for some reason (even though I've done things extremely similar in the past).