Change body in Middleware

I am writing a normal web application with TWIG and mysql. It uses an old mysql database what has some ugly strings. I like to change it “on the fly”. I thought the easiest way to change the body with some str_replace in the middleware. But I do not know what is the easiest way to change it.

What I read, I have to make a stream and write it, and something like this. But I only want to change a string. Is there an easiest way for it or isn’t?

Thanks

The amazing @akrabat wrote an article on this very thing you might want to check out: Filtering the PSR-7 body in middleware

1 Like