0

I have the following code:

echo "<li style='font-size:10pts;' class='news-item'>
        <a href='$link'>(".date("D, d M Y", strtotime($date)).") $description</a>
      </li>";

and the database field value for link is:

www.yahoo.com

Now when the echo statement above is executed, and I click on the link shown on page, it doesn't go to www.yahoo.com, but rather to www.mydomain.com/www.yahoo.com. This of course results in not found 404. How can I solve this please?

1
  • try http:// before the link Commented Feb 28, 2013 at 8:18

6 Answers 6

2

If you dont add http:// in front of your link, It will be executed as a directory:

echo "<li style='font-size:10pts;' class='news-item'>
        <a href='http://{$link}'>(".date("D, d M Y", strtotime($date)).") $description</a>
      </li>";

Or put http://www.yahoo.com/ in your database and use your original script.

Sign up to request clarification or add additional context in comments.

Comments

2

Put into database link with http://

Comments

1

add http or https ahead of link href.

$var = 'www.yahoo.com';

if(strpos($var, 'http://') !== 0) {
  return 'http://' . $var;
} else {
  return $var;
}

Comments

0

Try this,

$link = "http://".$link;

<a href='".$link."'>(".date("D, d M Y", strtotime($date)).") $description</a>

Comments

0

You have to add http:// to the beginning otherwise it is relative to the current location

Comments

0

Your $link = "www.yahoo.com"

your code <a href='$link'>

then output <a href='www.yahoo.com'>

When you use tag a href attribute should be <a href='http://www.yahoo.com'> to link to other domain.

Comments

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.