Eleven
Eleven

Reputation: 339

I am getting incorrect URL in anchor tag

I've this line of code. I'm trying to point my link on google for testing.

$content.="<a href='google.com' target=_blank>".$webSites['value']."</a>";

Instead of getting 'google.com' only, I'm getting as given below: (http://192.168.10.126/consumer/google.com).

Upvotes: 4

Views: 703

Answers (3)

user3129330
user3129330

Reputation: 11

Just add http:// in front of google.com

current:

$content.="<a href='google.com' target=_blank>".$webSites['value']."</a>";

New:

$content.="<a href='http://google.com' target=_blank>".$webSites['value']."</a>";

Upvotes: 0

Blaatpraat
Blaatpraat

Reputation: 2849

$content.="<a href='http://google.com' target=_blank>".$webSites['value']."</a>";

This should fix it. The reason is that your browser does not know that you're linking to an external resource, thus thinking that you're linking to a relative path. With adding http:// you force your browser to think that it's an absolute path.

Upvotes: 4

Albzi
Albzi

Reputation: 15619

Add http:// in front of google.com

So your code looks like this:

$content.="<a href='http://google.com' target=_blank>".$webSites['value']."</a>";

Without http://, your browser thinks that google.com is an internal link. Adding the http:// protocol lets the browser know you want to link to an external site.

Upvotes: 5

Related Questions