Answer the question
In order to leave comments, you need to log in
Replacing all external links through a redirect
Good afternoon.
There is a task to make a php filter that receives an html page as input and outputs the same page as output, but all external links change to /away.php?url=blabla
The task itself is not difficult, I will quickly do it through preg_replace, but preg_ has a limit of 100K, if the text is greater than this limit, then the functions do not work, you can of course raise the limit. but I want something more flexible.
What options do I see
1) Parse the DOM tree and change it there, but then non-valid documents will not be processed
2) Break the text into pieces less than 100k and change there, the question is how to break the text so that the border does not pass in the middle of the link
3) To analyze for each line, IMHO, is also not the best option.
Any ideas?
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question