|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2007-08-03 11:30 UTC] roast@php.net
Description:
------------
I use the functions ob_* with the internal functions to control the output,but in reality, things always happen out of expectation.
Reproduce code:
---------------
<?php
ob_start('md5');
echo "roast is a good boy";
echo ob_get_contents();
?>
Expected result:
----------------
e21b1aad689c47aeac5b7867c2c77afa
Actual result:
--------------
A瑔��)�
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Sat Oct 25 07:00:02 2025 UTC |
This is/was not a bug. The sample code had two fundamental issues: 1. as the buffer was not flushed before that line, the string returned by ob_get_contents() ('roast is a good boy') was passed to the output handler (md5) twice as the buffer was flushed at the end of the script 2. md5 expects two parameters to which OB passed the buffer contents and an int representing the OB context op. This int was interpreted by md5 as a bool true and hence the binary return value The following code achieves what OP wanted: <?php function md5Proxy($buffer, $phase) { return md5($buffer); }; ob_start('md5Proxy'); echo 'roast is a good boy'; ob_end_flush(); ?> Result: ------- e21b1aad689c47aeac5b7867c2c77afa