Home > Backend Development > PHP Problem > How to clear unknown output in php

How to clear unknown output in php

藏色散人
Release: 2023-03-10 13:42:01
Original
1498 people have browsed it

php method to clear unknown output: first open the corresponding PHP file; then add the statement "ob_start();require_once();ob_end_clean();" to the file header.

How to clear unknown output in php

The operating environment of this article: windows7 system, PHP7.1 version, DELL G3 computer

How to clear unknown output in php?

php clear unknown output

Sometimes we require_once() several files, and these files have output because of spaces in front or other reasons, A series of problems will appear later, including session. Generate pictures, etc. through php.

Can't find where the output is at this time. You can add

to the header of this file and

ob_start();
require_once();
require_once();
require_once();
ob_end_clean();
Copy after login

at the beginning. This way you can remove the unknown output in the file included in require_once

PS : Useful for AJAX XML

PHP Clear the echoed content

<div>passing </div>
<?PHP
echo &#39;here...&#39;;
// 代码 清除第一个echo的输出内容的“代码”
echo &#39;there...&#39;;
exit;
?>
Copy after login

Is there any The method is to only output the content of the second echo 'there...' (the premise is that neither echo code can be deleted, and there is content that must be output before (the div at the top), but you only want to get the content output by the second echo 'there...')

<?PHP
ob_start();
echo &#39;here...&#39;;
ob_clean();
ob_end_flush();
echo &#39;there...&#39;;
exit;
?>
Copy after login

Writing like this is achievable. Just buffer it when outputting, and then delete the cache

[Recommended learning: PHP video tutorial

The above is the detailed content of How to clear unknown output in php. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
php
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