note 57854 added to function.ob-start

From: Date: Sun, 16 Oct 2005 22:07:22 +0000
Subject: note 57854 added to function.ob-start
Groups: php.notes 
Request: Send a blank email to php-notes+get-97096@lists.php.net to get a copy of this message
If you're trying to use ob_start() in some PHP5 classes (probably works on PHP4 classes), this is the good way : <? class HTMLPage { //----------------------------------------------------------------- PUBLIC //----------------------------------------------------- Méthodes publiques public static function ConvertIntoSGML( $source ) // Mode d'emploi : //convertit une string en une SGML valide // // Renvoie : //la chaine traitée // // Algorithme : //analyse char par char de la chaine. Si un caractère est de nombre ASCII > 127, //conversion en son code SGML. { $newString = ''; for( $i = 0; $i < strlen( $source ) ; $i++ ) { $o = ord( $source{ $i } ); $newString .= ( ( $o > 127 ) ? '&#'.$o.';': $source{ $i } ); } return $newString; } public function FlushSite( $source ) { return $this->ConvertIntoSGML ( $source ); } //-------------------------------------------- Constructeurs - destructeur function __construct() // Mode d'emploi (constructeur) : //initialise la buffurisation // // Contrat : // { ob_start( array ( & $this , 'FlushSite' ) ); } //---- Fin du constructeur //------------------------------------------------------ Méthodes Magiques //------------------------------------------------------------------ PRIVE } // Example : $webdesign = new HTMLPage ( ); echo 'Héllo world'; // Will produce the source 'h&#233;llo world' ?> Without the & before $this, you'll loose your content because ob_start() will call the flushsite() function from a clone of the object and not the caller object himself. Note : call_back function must be public because ob_start() is in an extern scope from your class :) I hope this will help you! ---- Manual Page -- http://www.php.net/manual/en/function.ob-start.php Edit -- http://master.php.net/manage/user-notes.php?action=edit+57854 Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+57854&report=yes&reason=added+to+the+manual Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+57854&report=yes&reason=bad+code Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+57854&report=yes&reason=spam Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+57854&report=yes&reason=useless Delete: non-english -- http://master.php.net/manage/user-notes.php?action=delete+57854&report=yes&reason=non-english Delete: already in docs -- http://master.php.net/manage/user-notes.php?action=delete+57854&report=yes&reason=already+in+docs Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+57854&report=yes Reject -- http://master.php.net/manage/user-notes.php?action=reject+57854&report=yes Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#97096) next »