用php更改非php输出内容

WBOY
Release: 2016-06-23 14:29:31
Original
868 people have browsed it

用php更改非php输出内容...


前几天有个需求,就是将页面输出的内容进行过滤... 进行域名更换...
比如本来将输出的www.csdn.net/image/上面的图片内容,现在迁移到了cdn上面,域名更改为cdn.csdn.net/image/
再不更改模版的基础上,直接将输出进行修正...

实现过程
1.将所有输出放到output buffer里面
2.在php脚本结束后对output buffer进行修改过滤,再输出.

so测试如下:
原输出假设是如下:




用php更改非php输出内容



那么在输出html前,加入到php执行中如下代码即可进行html内容的替换



则输出变成



用php更改非php输出内容



重点在于
1.ob_xxx函数 output buffer控制
2.register_shutdown_function函数 注册一个脚本结束时运行的函数..

注意:
1.register_shutdown_function的这个输出必须是最后一个register的...
2.如果流程中有output buffer控制函数,需要具体情况具体分析,进行使用.
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!