hi, is there a simply way to detect URLs with PHP and make them links? i have seen this in Facebook comments and in many other websites. thanks in advance
what do you mean by "make them links" you want it to check if there is something written like this "google.com" if it sees that then it turns into <a href="google.com">google.com</a> ?
yes. if in the text is a url like "bla bla bla www.something.com bla bla bla" i want to turn this to "bla bla bla <a href="http://www.something.com" target="_blank">www.something.com</a> bla bla bla"
$string = " "; // you'll need to find a method to load the string with your text, pending on your source, it might be as simple as $post_data or some other variable already in use $search = "/(http[s]*:\/\/[\S]+)/"; $replace = "<a href='\${1}'>\${1}</a>"; $output = preg_replace($search, $replace, $string); PHP: