0

Is it possible to write a MySQL query to replace links inside an HTML hypertext link as follows:

ex:

hello world <a href="http://www.sample.com/">hello world2</a>
hello world2 <a href="http://www.sample.com/news.php">hello world2</a>

and turns this into:

hello world <a href="http://www.sample.com/?kid=1000">hello world2</a>
hello world <a href="http://www.sample.com/news.php?kid=1000">hello world2</a>

(basically adding an extra parameter to all links starting with http://www.sample.com)

yarek
  • 11,278
  • 30
  • 120
  • 219
  • 1
    [Docs](https://dev.mysql.com/doc/refman/5.7/en/string-functions.html#function_replace) say `REPLACE(str,from_str,to_str)` function should work – xQbert Apr 13 '17 at 14:51
  • No beacuse it should ADD to the END of the string and urls can be VARIOUS ! – yarek Apr 13 '17 at 20:04
  • Well, you could search for http: then find the position of the first " after http and substitute the " with your appended value. – xQbert Apr 13 '17 at 20:27
  • Could multiple http:// links be in a single text block? if so then I think the answer is not without a UDF for a regexreplace. http://stackoverflow.com/questions/986826/how-to-do-a-regular-expression-replace-in-mysql (trying to avoid re-inventing the wheel here) – xQbert Apr 13 '17 at 20:31
  • maybe by using regexp to dynamically "URL" then use replace? but this would have to be done in a loop if multiple urls per record. – xQbert Apr 13 '17 at 20:39

0 Answers0