I’m developing a PHP-based web-application in which you have a form with textarea inputs that can accept links via anchor tags. But when I tested it after adding a hyperlink as follows, it pointed to a non-existent local subdirectory:
<a href="www.link.com">link</a>
I realized that this was because I had not appended http:// before the link.
there might be cases where a user might input the link just as I did above. In such cases I don’t want the link to be pointing as it did above. is there any possible solution, such as automatically appending http:// before the link in case that it doesn’t exist? How do I do that?
—————————————-Edit———————————————
Please consider that the anchor tags are amidst other plaintext and this is making things harder to work with.
I’d go for something like this:
This is an easy and stable way to check for the presence of a protocol in a URL, and allows others (e.g.
ftp,https) that may be entered.