manix Posted August 14, 2011 Share Posted August 14, 2011 Hey, My question is, when a user submits a comment containing a link is there an easier way of putting it in an anchor tag rather than exploding the string by " " then finding the link putting the anchor blabla and finally imploding it all back together ? Quote Link to comment https://forums.phpfreaks.com/topic/244789-turn-link-into-link/ Share on other sites More sharing options...
xyph Posted August 14, 2011 Share Posted August 14, 2011 Regular Expressions are probably your best bet. It's going to be a pretty complex expression, potentially. Quote Link to comment https://forums.phpfreaks.com/topic/244789-turn-link-into-link/#findComment-1257364 Share on other sites More sharing options...
manix Posted August 14, 2011 Author Share Posted August 14, 2011 yeah I'd really rather stick to my example Quote Link to comment https://forums.phpfreaks.com/topic/244789-turn-link-into-link/#findComment-1257372 Share on other sites More sharing options...
xyph Posted August 14, 2011 Share Posted August 14, 2011 Then do that? You asked if there was an easier way... There is, but it requires knowledge of Regular Expressions. Alternately, you could use strpos( $body, 'http', $offset ) in a loop until it returns boolean false, searching for the next space and updating the offset with that. Store the start/end in an array, and use those offsets to pull the urls into an anchor tag afterwards. Quote Link to comment https://forums.phpfreaks.com/topic/244789-turn-link-into-link/#findComment-1257374 Share on other sites More sharing options...
manix Posted August 14, 2011 Author Share Posted August 14, 2011 Dejavu.. I'm starting to read, thank you xyph! Quote Link to comment https://forums.phpfreaks.com/topic/244789-turn-link-into-link/#findComment-1257381 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.