How do I capture PHP output into a variable?

后端 未结 4 1791
猫巷女王i
猫巷女王i 2020-11-27 04:04

I\'m generating a ton of XML that is to be passed to an API as a post variable when a user click on a form button. I also want to be able to show the user the XML before han

4条回答
  •  南方客
    南方客 (楼主)
    2020-11-27 04:47

    It sounds like you want PHP Output Buffering

    ob_start(); 
    // make your XML file
    
    $out1 = ob_get_contents();
    //$out1 now contains your XML
    

    Note that output buffering stops the output from being sent, until you "flush" it. See the Documentation for more info.

提交回复
热议问题