CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Beginner:
making urls links

 



darian
Deleted

Feb 2, 2000, 6:15 AM

Post #1 of 6 (1020 views)
making urls links Can't Post

Anyone know how to make a line like below able to be a clickable link? Just the url part not the whole line.

My Account - http://www.site.com/myaccount


brian.hayes
User

Feb 2, 2000, 6:39 PM

Post #2 of 6 (1020 views)
Re: making urls links [In reply to] Can't Post

Is this what your talking about?

<BLOCKQUOTE><font size="1" face="Arial,Helvetica,sans serif">code:</font><HR>



<A HREF="http://www.perlarchive.com">The #1 perl resource site!</A>

</pre><HR></BLOCKQUOTE>

Notice the text between:

<BLOCKQUOTE><font size="1" face="Arial,Helvetica,sans serif">code:</font><HR>



<A HREF=""> HERE!!! </A>

</pre><HR></BLOCKQUOTE>

Let me know if this helps.

Brian Hayes



darian
Deleted

Feb 2, 2000, 9:15 PM

Post #3 of 6 (1020 views)
Re: making urls links [In reply to] Can't Post

ok if you look at my original post you will see that the url is clickable. I did not put the <a href=> part in it but simply wrote out the url. How did you guys get that to become clickable as it is on a line with something else.


darian
Deleted

Feb 2, 2000, 11:37 PM

Post #4 of 6 (1020 views)
Re: making urls links [In reply to] Can't Post

yes I understand that but how do you search for the http:// part and make sure it stops before the first whitespace?


japhy
Enthusiast

Feb 3, 2000, 4:07 AM

Post #5 of 6 (1020 views)
Re: making urls links [In reply to] Can't Post

You can use a simple regular expression like the following

<BLOCKQUOTE><font size="1" face="Arial,Helvetica,sans serif">code:</font><HR>


$string =~ s{
(
(?:ftp | https?) # match specific protocols
:// # match the ://
\S+ # match as many non-spaces as possible
)
}{
my $url = $1;
my ($junk) = $url =~ s!([^\w+&=/]*)$!!;
<a href="$url">$url</a>$junk
}xge;
</pre><HR></BLOCKQUOTE>

The left-hand side of the regex basically pulls out what we think is a URL. The right-hand side evaluate some Perl code to try and remove any non-URL junk at the end of the URL. For instance, if the string held "Visit my web site at http://www.foo.com/~me.", we wouldn't want to keep that . in the link, because it would foul things up. I'm not sure my approach is a spectacular one, but it should work well at not including things in the URL section that it shouldn't.


Borderline
Deleted

Feb 3, 2000, 10:22 AM

Post #6 of 6 (1020 views)
Re: making urls links [In reply to] Can't Post

darian,

Most CGIs that do this just look for the http:// or https:// in the text and then just take every non-space/non-newline character after it and put it in a <a href> tag.

Scott

 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives