jaymc Posted November 8, 2007 Share Posted November 8, 2007 Rather than make my own function Im just wondering if there is a predefined one or one you guys know of I want to have something that will turn a link someone has entered (www.website.com) and wrap it in html to make it a link so: <a href="http://www.website.com" target="blank">www.website.com</a> Link to comment https://forums.phpfreaks.com/topic/76538-make-url-html-link/ Share on other sites More sharing options...
The Little Guy Posted November 8, 2007 Share Posted November 8, 2007 Nope, no function Link to comment https://forums.phpfreaks.com/topic/76538-make-url-html-link/#findComment-387625 Share on other sites More sharing options...
cooldude832 Posted November 8, 2007 Share Posted November 8, 2007 yes, kinda use regex and say replace anything that matches anything.www.anything.anythinghere with <a href=\"".$match."\" target=\"_blank"\">".$match."</a>"; you will need to discovery the matches and apply the complex replacement in a two fold step, but get your regex pattern built first. Link to comment https://forums.phpfreaks.com/topic/76538-make-url-html-link/#findComment-387627 Share on other sites More sharing options...
PHP_PhREEEk Posted November 8, 2007 Share Posted November 8, 2007 We don't know how you are accepting your input. I'll leave that problem for you... just remember, garbage in, garbage out. So let's say you have an input that has satisfied your script, and we now have it in a variable. You would do the following: <?php $weblink = 'www.somesite.com'; // this is the final result of your script processing the user input $weblink = '<a href="http://' . $weblink . '" target="blank">' . $weblink . '</a>'; echo $weblink; ?> PhREEEk Link to comment https://forums.phpfreaks.com/topic/76538-make-url-html-link/#findComment-387650 Share on other sites More sharing options...
cooldude832 Posted November 8, 2007 Share Posted November 8, 2007 Well its a substr of a large string so you are going to need to find said substr. Which is going to need to be found using a regex to find all the matches. Its a complicated thing, but can be done for presentation purposes, I wouldn't be surprised if one exist already Link to comment https://forums.phpfreaks.com/topic/76538-make-url-html-link/#findComment-387655 Share on other sites More sharing options...
jaymc Posted November 9, 2007 Author Share Posted November 9, 2007 Yes I see, lets say the string is this Hey my website is www.website.com go and visit it please, thanks How are we going to pick out www.website.com I suppose you could explode the string by " ", then search through each elements of the array for "www." for instance, if it meets it, do the a href stuff Its a bit long winded though to do that, any better ideas? The regex seems good but its extreemly messy, I've never managed to get my head around it. Any examples? Cheers Link to comment https://forums.phpfreaks.com/topic/76538-make-url-html-link/#findComment-388003 Share on other sites More sharing options...
cooldude832 Posted November 9, 2007 Share Posted November 9, 2007 go post in the regex help for a pattern to detect any url or google it and come back here with that pattern I will explain it then. Link to comment https://forums.phpfreaks.com/topic/76538-make-url-html-link/#findComment-388006 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.