When I use middleware to remove stuff out of the generated content, my html is wierd.
Example:
public function __invoke($request, $response, $next)
{
$response = $next($request, $response);
$response->getBody()->rewind();
$response->getBody()->write("change the html");
$content = (string)$response->getBody();
var_dump($content);
die();
return $response;
}
What happens is that the first characters of my HTML are the canged ones, but the rest of the HTML is my old HTML. (I think it’s because the string length is allready set.)
I can expand the body with success, but never shrink it, which is wierd.
Is this what you mean? The reason behind this is a so called stream. The rewind method just changes the offset in the stream to the first position, but it does’t clear the previous content in the stream.