Change non-PHP output content with PHP ...
A few days ago there is a need to filter the content of the page output ... Change the domain name ...
For example, the output of the www.csdn.net/image/above the image content, now migrated to the CDN above, the domain name changed to cdn.csdn.net/image/
Do not change the template on the basis of direct output correction ...
Implementation process
1. Place all outputs in output buffer
2. After the end of the PHP script, modify the output buffer to filter, and then export.
The so test is as follows:
The original output hypothesis is as follows:
Then, before outputting the HTML, add the following code to the PHP execution to replace the HTML content
The output becomes
The point is
1.ob_xxx function Output Buffer control
The 2.register_shutdown_function function registers a function that runs at the end of a script:
Attention:
This output of 1.register_shutdown_function must be the last register ...
2. If there is an output buffer control function in the process, it needs to be analyzed and used in specific cases.