Welcome, Guest. Please login or register.
Did you miss your activation email?


Login with username, password and session length

Search

 
Advanced search

8040 Posts in 1853 Topics- by 2099 Members - Latest Member: roi
Calendar Script CommunityCustomizationHacks and Mods (Moderators: scott, DanO, Marty)autolink for www.sitename.xxx
Pages: [1]   Go Down
Print
Author Topic: autolink for www.sitename.xxx  (Read 367 times)
0 Members and 1 Guest are viewing this topic.
simma
New Member
*

Karma: 0
Offline Offline

Posts: 0


WWW
« on: October 03, 2003, 11:04:00 PM »

I would like to enable autolinks for URLs that do not include the leading http://
.... many of my users forget to add it.
Can anyone provide me the appropriate string $text =~ ....
I tyried to duplicate and modify the existing one and failed.

thanks

Logged
DanO
Moderator
Full Member
*****

Karma: 13
Offline Offline

Posts: 227

Please don't PM me. Post in the open forum.


WWW
« Reply #1 on: October 04, 2003, 12:50:00 PM »

** I would like to enable autolinks for URLs that do not include the leading http:// **

There has to be some sort sequence of characters to identify a URL. If the URLs entered start with www...,  the line below should work.

$text =~ s#(^|\s)(www\.\S*)#$1<A HREF="http://$2" $target>$2</A>#gs;

Be sure not to use both the original and this as it will cause malforming of URLs. Maybe something like:

if (text !~ #http://#)
{
$text =~ s#(^|\s)(www\.\S*)#$1<A HREF="http://$2" $target>$2</A>#gs;
}

Dan O.

------------------

Logged
simma
New Member
*

Karma: 0
Offline Offline

Posts: 0


WWW
« Reply #2 on: October 04, 2003, 04:43:00 PM »

Dan,

great it worked ... but with the first suggestion.
In other words with the following sequence

       $text =~ s#(^|\s)(http://\S*)#$1<A HREF="$2" $target>$2</A>#gs;
       $text =~ s#(^|\s)(www\.\S*)#$1<A HREF="http://$2" $target>$2</A>#gs;
       $text =~ s#(^|[^\w-])([\w.-]*@[\w.-]+(\.[\w-]+)+)#$1<A HREF="mailto:$2"$

I do add links to http://websitename  and www.webasitename..  
and e-mail addresses, without any apperant problem.
I do not see the side effect that you are describing.

While if I use the
if (text !~ #http://#)
{
$text =~ s#(^|\s)(www\.\S*)#$1<A HREF="http://$2" $target>$2</A>#gs;
}

it doesn't work (there is a problem in the if statement)

thanks

------------------

Logged
DanO
Moderator
Full Member
*****

Karma: 13
Offline Offline

Posts: 227

Please don't PM me. Post in the open forum.


WWW
« Reply #3 on: October 04, 2003, 07:31:00 PM »

** I do add links to http://websitename  and www.webasitename..  **

Try http://www.websitename  and see what you get.

Dan O.

------------------

Logged
peter
Guest
« Reply #4 on: March 07, 2004, 12:33:00 PM »

Hey, I looked at this and I think I figured out the problem with the if statement.  It works for me if I add "$" before "text" and use quotes instead of number signs, like this:

if ($text =~ "http://")

When I replaced the existing line that handles the "http://..." case with the if statement, links starting with "http://" were no longer processed.  I got them to work by extending the if statement, so the section looks like this:

 if ($text !~ "http://")
 {
   $text =~ s#(^|\s)(http://\S*)#$1<A HREF="$2" $target>$2</A>#gs;
 }
 else
 {
   $text =~ s#(^|\s)(www\.\S*)#$1<A HREF="http://$2" $target>$2</A>#gs;
 }
 $text =~ s#(^|[^\w.-])([\w.-]*@[\w.-]+\.\w+)#$1<A HREF="mailto:$2">$2</A>#gs;

Is that a good way to do it or is there a better way?

Logged
peter
Guest
« Reply #5 on: March 07, 2004, 12:36:00 PM »

Oops - that first if statement should have been

if ($text !~ "http://")

Logged
peter
Guest
« Reply #6 on: March 07, 2004, 12:41:00 PM »

Whoops!  The second should have been

if ($text =~ "http://")

Logged
Pages: [1]   Go Up
Print
Jump to: