john john - 3 months ago 15
PHP Question

Make a url clickable gathered from database

I have this line of code.

<p> Linkedin: <?= $user_info['portfolio_website'] ?></p>


The portfolio_website is a database column from user profiles where urls are stored.

Via the code above the urls corresponding to the user is displayed on the website page.

But it's just text and it isn't clickable.

So my question is: How can I make the url clickable?

Answer

By wrapping the url in an anchor tag. Also, you could also hide the url and put any other text to show as the link:

<p> Linkedin: 
    <a href="<?= $user_info['portfolio_website'] ?>">
        Some text here
    </a>
</p>

To show the url as the clickable link do this:

<p> Linkedin: 
    <a href="<?= $user_info['portfolio_website'] ?>">
        <?= $user_info['portfolio_website'] ?>
    </a>
</p>