Welcome Guest, Not a member yet? Register   Sign In
How to make a text field linkable
#1

[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
#2

[eluser]SmokeyJoe[/eluser]
if $userDetails['website'] is like http://www.somewebsite.com

Code:
<a href="&lt;?php echo $userDetails['website']; ?&gt;" target="_blank">&lt;?php echo $userDetails['website']; ?&gt;</a>

should work

Code:
&lt;?php echo anchor($userDetails['website'],$userDetails['website'],'target="_blank"'); ?&gt;
should work

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']))




Theme © iAndrew 2016 - Forum software by © MyBB