Is there any way to return HTML in a PHP function? (without building the return value as a string)

后端 未结 8 1747
误落风尘
误落风尘 2020-12-12 11:55

I have a PHP function that I\'m using to output a standard block of HTML. It currently looks like this:


          


        
8条回答
  •  一生所求
    2020-12-12 12:06

    You can use a heredoc, which supports variable interpolation, making it look fairly neat:

    function TestBlockHTML ($replStr) {
    return <<
        

    {$replStr}

    HTML; }

    Pay close attention to the warning in the manual though - the closing line must not contain any whitespace, so can't be indented.

提交回复
热议问题