找到你要的答案

Q:PHP Return HTML (Laravel / Lumen Framework)

Q:PHP返回HTML(laravel /管腔框架)

I have a helper function with the following

Note I am using the following to parse content

https://github.com/erusev/parsedown

function display_docs_page($name){

    // Get Docs URL
    $docs_url = config('docs.docs_url');

    // Get File URL
    $file_url = $docs_url.'/'.$name.'.md';

    // Check If File Exists
    if (file_exists($file_url)) {

        // get raw file data
        $raw_file_data = file_get_contents($file_url);

        // convert data to html
        $parsedown = new Parsedown();

        return $parsedown->text($raw_file_data);

    } else {

        // 404
        return 'not_found';

    }

}

However when I run my function

return view('greeting', [
     'contents' => display_docs_page(config('general.homepage')),
]);

and try to echo out the variable so in blade

{{ $contents }}

I just just RAW html code. So its displaying the html data but its just raw code the browser isn't interpreting it.

我有一个辅助函数

注意我使用以下内容来解析内容

https://github.com/erusev/parsedown

function display_docs_page($name){

    // Get Docs URL
    $docs_url = config('docs.docs_url');

    // Get File URL
    $file_url = $docs_url.'/'.$name.'.md';

    // Check If File Exists
    if (file_exists($file_url)) {

        // get raw file data
        $raw_file_data = file_get_contents($file_url);

        // convert data to html
        $parsedown = new Parsedown();

        return $parsedown->text($raw_file_data);

    } else {

        // 404
        return 'not_found';

    }

}

然而,当我运行我的功能

return view('greeting', [
     'contents' => display_docs_page(config('general.homepage')),
]);

试着在叶片中反射出变量

{{ $contents }}

我只是原始HTML代码。所以它显示HTML数据,但它只是原代码的浏览器不解释。

answer1: 回答1:

In Lumen / Laravel 5 you should use {!! !!} to output variable without escaping:

{!! $contents !!} 

Read more: http://laravel.com/docs/master/upgrade#upgrade-5.0 (Blade Tag Changes section)

在鹿门山,你应该使用{ 5 / laravel!!!}输出变量不转义:

{!! $contents !!} 

阅读更多:HTTP:/ / laravel。COM /文档/主/升级# upgrade-5.0(叶片标签的变化部分)

answer2: 回答2:

Its because by default laravel escaped everything in {{ }}, you must use {!! $contents !!} instead of {{ $contents }}

因为默认了一切{ { } laravel },你必须使用{!$内容!}而不是{ $ $ } }

php  laravel  lumen