I think it is clear but here is an example:
<a href="https://stackoverflow.com/">https://stackoverflow.com/</a>
The code makes this real link: https://stackoverflow.com/
Is there a simpler way to do this?
I take it you want something like:
<a>http://stackoverflow.com/</a>
That would look logical, but what if you want to have custom text, eg POTATO?
This would make no sense.
<a>POTATO</a>
The text in the link is really just the clickable text, not where the link points to. Also, you can have image in the link, or other things. The href
attribute is what really matters in HTML.
This is right:
<a href="http://stackoverflow.com/">http://stackoverflow.com/</a>
<a href="http://potato.com/">POTATO</a>
To do something like what you want, the best option is to use some kind of pre-processor, like BBCode parser (BBCode is the format used on bulletin boards).
In BBCode, you could have
[url]http://stackoverflow.com/[/url]
translate to
<a href="http://stackoverflow.com/">http://stackoverflow.com/</a>
Note that BBCode also allows
[url=http://stackoverflow.com]Link text[/url]
or, with the potato example
[url=http://potato.com]POTATO[/url]
You can make your own parser that does something similar with regular expressions, eg. using preg_replace
.