jakubsnm Posted September 26, 2009 Share Posted September 26, 2009 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. 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 just noticed typin "www.mysite.com" and clicking preview produces a proper link so there must be a way... Link to comment https://forums.phpfreaks.com/topic/175607-convert-database-field-to-links-no-matter-what/ Share on other sites More sharing options...
MadTechie Posted September 26, 2009 Share Posted September 26, 2009 What's the code that converts "www.userslink.com" to "http://www.mysite.com/www.userslink.com" ? or even converts "www.userslink.com" to a link Link to comment https://forums.phpfreaks.com/topic/175607-convert-database-field-to-links-no-matter-what/#findComment-925348 Share on other sites More sharing options...
monkeytooth Posted September 26, 2009 Share Posted September 26, 2009 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> Link to comment https://forums.phpfreaks.com/topic/175607-convert-database-field-to-links-no-matter-what/#findComment-925366 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.