Okay, the header question may sound confusing, yeah, I too was confused. Anyway, what I wanted is this:
Say I have this line of text,
The quick brown @fox jumps @over the @lazy dog.
This line of text is a dynamically fetched ‘single line’ from the database, not an array of texts. Assuming the texts with first letter as ‘@’ are links to a page or something, I want that I can specify on where to put my anchor tag, in my case, I want to put anchor tag on each of the texts starting with ‘@’.
I tried explode, but it seems explode is not the answer to this. Can someone help me out here? Thanks.
You don’t want to use
explodefor that, but a regex. To match multiple occurences,preg_match_allis the deal.You certainy might want to use
preg_replaceto transform them into links. Or better yetpreg_replace_callbackto move some logic into a handler function.