0

i have a database that stores the url example facebook.com i dispalyed the value in my table and i posted the same value in a href

            <a href="<?php echo $url['url']; ?>" target="_blank">
            <?php echo $fet_2['urlname']; ?></a>

so when i click the urll is opening in new tab like domain.COM/folder/folder/www.facebook.com and the fb page is not loaded. i want to load the fb page when i click the name. please help me

2
  • 1
    Append http:// to your href... Commented Feb 7, 2013 at 2:08
  • No problem -- glad we could help. Posted some additional information to consider. Good luck. Commented Feb 7, 2013 at 2:29

2 Answers 2

1

I would think that you are missing the http:// from the URL, and that's why you are directed to inside the domain looking for that page.

You can solve it like this.

<a href="http://<?php echo $url['url']; ?>" target="_blank">
Sign up to request clarification or add additional context in comments.

Comments

1

As I mentioned in my comment, make sure the href has an "http://" in the URL. If not, the site will try to open in your current domain.

If some of the URLs in your database have the http://, then you need to do a check before prepending. Use something like this:

How to add http:// if it's not exists in the URL?

function addhttp($url) {
    if (!preg_match("~^(?:f|ht)tps?://~i", $url)) {
        $url = "http://" . $url;
    }
    return $url;
}

Good luck.

1 Comment

magnet:// ;) \w+:// would be more flexible, but this will probably cover all the cases OP has in mind anyway.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.