Jump to content

Convert database field to links no matter what...


jakubsnm

Recommended Posts

I have a site where users enter their site link but must enter http:// in front of the URL or their link wont work. Is there a workaround.  :shrug:

 

Right now if a user enters their link as "www.userslink.com" then the link gets output as "http://www.mysite.com/www.userslink.com" and ends up as a broken link.

 

The variable I use to call the link is

<?=$item_details['url']; ?>

 

Right now my code is

<a target="_blank" rel="nofollow" href="<?=$item_details['url']; ?>"><?=$item_details['url']; ?></a>

 

I would really love to get rid of the "You must start your link with http://" text on my site...

 

Cheers to whoever solves this  :o

 

just noticed typin "www.mysite.com" and clicking preview produces a proper link so there must be a way...

You need to modify your how your displaying the links when pulled from the database.

 

I would say, when pulled from the database.

<?php
$match2link = "http://";
$link2check = $database_output;
$modLink = (strstr($link2check,$match2link)?”no”:”yes”);

if($modLink == "yes"){$display_link = "http://" . $link2check;}
elseif($modLink == "no"){$display_link = $link2check;}
else{$display_link = "#linkerror";}
?>
<a href="<?php echo $display_link; ?>" target="_blank"><?php echo $display_link; ?></a>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.