¿Cómo proporcionar un enlace externo usando echo en php?
Frecuentes
Visto 1,787 veces
1
I am trying to store some link in database, for example www.google.com
. Lets say after pulling the value from database I stored it in $url
. Now, I am trying to set the link by doing
echo "<a href=$url>link</a>"
Now, the problem - whenever I click on the link the links goes to www.mydomain.com/www.google.com
2 Respuestas
5
Tienes que agregar http://
to the beggining of the link. EG:
echo "http://$url";
:)
Respondido 28 ago 12, 15:08
2
This might depend on the browser, but links are always relative and outbound links should include the correct http
or https
protocol specification.
Respondido 28 ago 12, 15:08
No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas php sql echo or haz tu propia pregunta.
Or store the "http://" as part of the string in the database. This is probably preferred, since you'll occasionally need to differentiate between http and https. (Or mailto: or tel: or whatever.) - Alex Howansky
Actually, I think I'd just do a string check on the link first. If it already starts with a protocol indicator, then echo it as is, else prepend http:// to it. Then you can store them either way. - Alex Howansky
Can you please provide the code you're using? It should work providing
$url
tiene el prefijohttp://
- Andy