I was creating a script and it includes a posting script but I want users to directly copy a link from anywhere else and when they post it the link text should automatically convert the link to link-element (<a>).
So for example this:
Ask this on http://stackoverflow.com now
to become
Ask this on <a href="http://stackoverflow.com">http://stackoverflow.com</a> now
I have tried the str_replace() function but it wasn’t the solution.
Can anyone tell me a solution to this?
There are several solutions out there for this, most of them being poorly written and incomplete. In this situation I would advise to use an already existing solution of one of the big frameworks, there is no need to reinvent the wheel.
For example, this article on Zenverse describes the way WordPress handles this.
Let me add the snippet here for further reference:
An example usage as written in the linked article: