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

后端 未结 8 1782
误落风尘
误落风尘 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:27

    This may be a sketchy solution, and I'd appreciate anybody pointing out whether this is a bad idea, since it's not a standard use of functions. I've had some success getting HTML out of a PHP function without building the return value as a string with the following:

    function noStrings() {
        echo ''?>
            
    [Whatever HTML you want]

    The just 'call' the function:

    noStrings();
    

    And it will output:

    [Whatever HTML you want]

    Using this method, you can also define PHP variables within the function and echo them out inside the HTML.

提交回复
热议问题