Use PHP to change non-PHP output content

Source: Internet
Author: User
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.

  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.