I have a text which contains hyperlinks, some hyperlinks contain spaces and I want to convert them into %20.
For example:
To make hyperlinks <a href="http://www.link-to-my-page.com/page 1.html">Page 1</a>
If I convert above text using rawurlencode function it returns
To%20make%20hyperlinks%20%3Ca%20href%3D%22http%3A%2F%2Fwww.link-to-my-page.com%2Fpage%201.html%22%3EPage%201%3C%2Fa%3E
I wrote following RE to convert space into %20 in links only but I am not sure how to apply space (\s)* with preg_replace.
/(http|https|ftp|ftps)(\:\/\/[a-zA-Z0-9\-\.]+)(\s)*\.[a-zA-Z]{2,4}(\/\S*)?/
Any help would be greatly appreciated.
Thanks