How to make a text field linkable - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20) +--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23) +--- Thread: How to make a text field linkable (/showthread.php?tid=58608) |
How to make a text field linkable - El Forum - 06-29-2013 [eluser]margsot[/eluser] I am using a text field in my database which stores the website url of a user, and this code to view this field on the page. Code: <?php echo $userDetails['website']; ?> What i want is to make this field linkable in _blank window I tried to insert a tag before the code above but doesnt work Any solution? Thanks How to make a text field linkable - El Forum - 07-24-2013 [eluser]SmokeyJoe[/eluser] if $userDetails['website'] is like http://www.somewebsite.com Code: <a href="<?php echo $userDetails['website']; ?>" target="_blank"><?php echo $userDetails['website']; ?></a> should work Code: <?php echo anchor($userDetails['website'],$userDetails['website'],'target="_blank"'); ?> so you just have to check via regular expression if $userDetails['website'] has a correct format Code: if(preg_match('/^(http|https|ftp):\/\/([A-Z0-9][A-Z0-9_-]*(?:\.[A-Z0-9][A-Z0-9_-]*)+):?(\d+)?\/?/i', $userDetails['website'])) |