English Deutsch Français Italiano Español Português 繁體中文 Bahasa Indonesia Tiếng Việt ภาษาไทย
All categories

I want to extract a link from a string for example:

If someone writes,

Hi, checkout my website http://www.ask.com which is fantastic.

Now this above is a string, which i am storing in MySQL database but i want to convert http://www.ask.com into a link so that when i click on it, it should link to this website.

I am using PHP and MySQL.
On my website, for example, when I get a feedback, sometimes people write their website links, so when I view them, i have to copy and paste the link into the browser as I am not able to click on this string, instead when i view the feedbacks, i should be able to click on the links.

So how do i convert this part of the string into a link?

2006-07-05 08:11:23 · 7 answers · asked by Manish 5 in Computers & Internet Programming & Design

An example,

When you type a plain text email and include a link as well, when a viewer opens this email, this link which was in text is automatically converted into a link. How?

2006-07-05 08:15:48 · update #1

Don;t answer me by saying insert 2006-07-05 08:25:39 · update #2

None of the answers helped so far.

Anyways, i found the way and it is working perfectly ok so far.

2006-07-05 08:47:07 · update #3

7 answers

It would be best to use a regular expression for this:

//get the data from mysql setting $comment with the comment field
$regExp = "/(http://.*\w)/i";
$newComments = preg_replace($regExp, "$1" ,$comment);
echo $newComments;
?>

2006-07-05 09:40:10 · answer #1 · answered by John J 6 · 0 0

not exactly sure on the syntax since I am not fluent in php but you would do something like this. First find the start and end of the URL by searching your text for http:// for the start then use this as the starting point to find your domain suffix - like .com or .net - which you use as the position for the end of the URL. Then replace the http:// part with the start of an anchor tag for your link. Then replace your URL string with ">urlString to close off you link text

urlStringStart = find(myText, "http://")
urlStringEnd = find(myText, ".com", urlStringStart)
// you will need to check for the different suffixes here if you don't find .com, .net, etc.
urlString = mid(myText, urlStringStart, urlStringEnd)
myText = replace(myText, urlString, "#urlString#")

2006-07-05 08:26:20 · answer #2 · answered by jmfc 4 · 0 0

I'm surprised your comment management software doesn't inlcude the opportunity to automatically recognize URL's that begin with http.

PHP can process any text it gets, and I've found an example that will pull all URL's from a page (below). Maybe that can act as a starting point for you.

2006-07-05 08:19:11 · answer #3 · answered by jv 2 · 0 0

It is called HTML. Hyper Text Markup Language. To insert a link, do something like this: Ask. Just insert this line of text somewhere in your program and it should turn up to be a link. Hope this works.

2006-07-05 08:23:27 · answer #4 · answered by Thor 5 · 0 0

Parse the string using VBscript string functions like Instr, Mid. Hone in on the "http" part and then look for the last . in the string

2006-07-05 08:16:08 · answer #5 · answered by Anonymous · 0 0

open Microsoft Word and write the site and copy + paste it

or

add the http thingy or the link won't work

2006-07-05 08:14:16 · answer #6 · answered by austin_penguin 4 · 0 0

fedest.com, questions and answers