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

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

    Template File

    {title}

    {username}

    PHP

    if (($text = file_get_contents("file.html")) === false) {
        $text = "";
    }
    
    $text = str_replace("{title}", "Title Here", $text);
    $text = str_replace("{username}", "Username Here", $text);
    

    then you can echo $text as string

提交回复
热议问题