ebolt007 Posted March 30, 2012 Share Posted March 30, 2012 I'm trying to write a piece that checks to see if something someone posts is a url or if it's just a url in a sentence. Basically, I want it so if someone puts in www.phpfreaks.com (then it does something) but if they put I am on www.phpfreaks.com where are you? (Then it does something else) Like the first one will get the dom of the page and post that, and the second one would just post the sentence with the url in it as a link. So I am getting my post $Post checking if there is a www or .com or .net or .gov in it $find2 = 'www.'; $find3 = '.com'; $find4 = '.net'; $find5 = '.gov'; if((strstr($Post, $find2) ==true)||(strstr($Post, $find3) ==true)||(strstr($Post, $find4) ==true)||(strstr($Post, $find5) ==true)){ then do I explode the whole thing, or what would I do in here with the $Post? some people might put in just phpfreaks.com others might put in http://www.phpfreaks.com and others might put in http://www.phpfreaks.com/forums/index.php?action=post;board=1.0 so I need to find the www. and or .com and find the first space before that, and after that and cut out the middle section, but I'm at a loss. } Quote Link to comment https://forums.phpfreaks.com/topic/260035-find-url-but-not-if-its-in-a-sentance/ Share on other sites More sharing options...
jcbones Posted March 30, 2012 Share Posted March 30, 2012 You need to find it using preg_match, You can use the multi-line modifier to get URL's that are on a line by themselves, ignoring URL's that are on lines consisting of other characters. Quote Link to comment https://forums.phpfreaks.com/topic/260035-find-url-but-not-if-its-in-a-sentance/#findComment-1332864 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.