envexlabs Posted January 9, 2009 Share Posted January 9, 2009 Hey, Lets use twitter for an example. I have a string that says: Hey everyone, check out my new portfolio site at mysweetsite.com If the user was made to put a tag in from the the url, how would i extract the url from the string so i could format it properly? Thanks. Quote Link to comment Share on other sites More sharing options...
MatthewJ Posted January 9, 2009 Share Posted January 9, 2009 http://us.php.net/preg_match Quote Link to comment Share on other sites More sharing options...
RussellReal Posted January 9, 2009 Share Posted January 9, 2009 preg_replace preg match would just match it lol but you shouldn't do whatever.*** match: www.whatever.*** or (http://[^ ]+) Quote Link to comment Share on other sites More sharing options...
MatthewJ Posted January 9, 2009 Share Posted January 9, 2009 lol? Is it 1995 where you live? I misread and thought he wanted to "extract" the url for another use. But it should have led him down the road pretty quickly to preg_replace() good catch though Quote Link to comment Share on other sites More sharing options...
RussellReal Posted January 9, 2009 Share Posted January 9, 2009 Is 1995 a bad thing? I was 5 then actually and I'd love to be 5 again lol! Quote Link to comment Share on other sites More sharing options...
envexlabs Posted January 10, 2009 Author Share Posted January 10, 2009 Hey, I think i messed up on my explanation. originally $string would = "Hey everyone, check out my new portfolio site at mysweetsite.com" I would like to work some magic and have $string echo out: Hey everyone, check out my new portfolio site at <a href="http://mysweetsite.com">mysweetsite.com</a> So that it renders out a clickable link. would preg_replace() still be the answer? Quote Link to comment Share on other sites More sharing options...
RussellReal Posted January 10, 2009 Share Posted January 10, 2009 What if you have bad grammar and you did "welcome to whatever.come to this page and lets see!!" whatever.com would become a link and the e will be left out.. you need either www. or http:// to let the parser know its a link.. Quote Link to comment Share on other sites More sharing options...
envexlabs Posted January 11, 2009 Author Share Posted January 11, 2009 Ok, lets say that the user needed the http:// in front of the link. Is preg_replace() still the best route? Quote Link to comment Share on other sites More sharing options...
RussellReal Posted January 11, 2009 Share Posted January 11, 2009 if they always supply "http://" then you could do strpos() for "http://" and then another strpos() for a " " (space) and then substr() the difference references: strpos substr 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.