bfarre01 Posted January 11, 2007 Share Posted January 11, 2007 I am trying to create some interesting output from a custom Exception but I am missing a step. The problem comes in where the HTML in my __toString() output string is encoded. Below is as simple a custom Exception and __toString() as I could come up with. I just threw it all in junk.php and let it rip.How can I prevent the HTML from being encoded? OrHow can I code the __toString() to generate HTML output?[code]<?phpclass MyException extends Exception{ public function __construct($m = 'unknown', $c = 0) { parent::__construct($m, $c); } public function __toString() { return ": <b>Hello</b>"; }}throw new MyException();?>[/code]Output at command line:[code]PHP Fatal error: Uncaught : <b>Hello</b> thrown in C:\...\junk.php on line 11[/code]Output in Browser:[code]<b>Fatal error</b>: Uncaught : <b>Hello</b> thrown in <b>C:\...\junk.php</b> on line <b>11</b><br />[/code]Desired Browser Output:[code]<b>Fatal error</b>: Uncaught : <b>Hello</b> thrown in <b>C:\...\junk.php</b> on line <b>11</b><br />[/code] Link to comment https://forums.phpfreaks.com/topic/33763-exception-__tostring-trying-to-get-html-output/ Share on other sites More sharing options...
trq Posted January 11, 2007 Share Posted January 11, 2007 I dont think you can. Link to comment https://forums.phpfreaks.com/topic/33763-exception-__tostring-trying-to-get-html-output/#findComment-158320 Share on other sites More sharing options...
bfarre01 Posted January 11, 2007 Author Share Posted January 11, 2007 Kept digging and found a possilbe solution but it may be a little heavy handed. If there is a better solution out there please share. I added "ini_set('html_errors', 0);" to __toString(). I lost some of the other formatting but what I wanted to show up does. As I was planning to put HTML formatted lists the loss of the bold on the 'Fatal Error', the file name, and line number is a small price to pay. Below is the new __toString(); [code]public function __toString() { ini_set('html_errors', 0); return ": <b>Hello</b>"; }[/code] Link to comment https://forums.phpfreaks.com/topic/33763-exception-__tostring-trying-to-get-html-output/#findComment-158369 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.