Jump to content

Convert database field to links no matter what...


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>

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.