Find and replace text.

We have links like this in the text…

How to change these links to watch?

Answer 1, authority 100%

Well, like this:

preg_replace('/http:\/\/[^\s]+\.html/','<a href="$0"></a>',$str);

Thing replaces all lines that start with http://, consist of anything but spaces, and end with .html.

More general case:

preg_replace('/(http:\/\/)|(www\.)[^\s]+\.[a-z34]{2,6}/','<a href="$0"></a>',$str);

In this case, it is possible for the link to start with www or http and end with any (almost) extension. 34 is two characters to cover extensions like mp3, mpeg4